From 3eec2ce071dbdba6b26dba599c17282f3772807a Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Tue, 24 Jul 2018 10:51:25 -0400 Subject: [PATCH 1/3] Document file_relative Twig function --- reference/twig_reference.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 63ebb1a46aa..d70becfe5f2 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -637,6 +637,27 @@ file_link Generates a link to the provided file and line number using a preconfigured scheme. +file_relative +~~~~~~~~~~~~~ + +.. code-block:: twig + + {{ file|file_relative }} + +``file`` + **type**: ``string`` + +Returns the relative path from the passed absolute file path. For example, +assume you've a project in the following directory: ``/var/www/blog/``. + +.. code-block:: twig + + {{ '/var/www/blog/templates/admin/index.html.twig'|file_relative }} + {# templates/admin/index.html.twig #} + +If the passed path doesn't match the project directory, a ``null`` value +will be returned. + .. _reference-twig-tags: Tags From 67460dc874d5fd2383949c0cf9107f22568d8d20 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 25 Jul 2018 09:18:38 +0200 Subject: [PATCH 2/3] Reword and added the versionadded directive --- reference/twig_reference.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index d70becfe5f2..817835b1fa2 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -640,6 +640,9 @@ a preconfigured scheme. file_relative ~~~~~~~~~~~~~ +.. versionadded:: + The ``file_relative`` filter was introduced in Symfony 4.2. + .. code-block:: twig {{ file|file_relative }} @@ -647,15 +650,15 @@ file_relative ``file`` **type**: ``string`` -Returns the relative path from the passed absolute file path. For example, -assume you've a project in the following directory: ``/var/www/blog/``. +It transforms the given absolute file path into a relative file path from the +project's root directory: .. code-block:: twig {{ '/var/www/blog/templates/admin/index.html.twig'|file_relative }} - {# templates/admin/index.html.twig #} + {# if project root dir is '/var/www/blog/', it returns 'templates/admin/index.html.twig' #} -If the passed path doesn't match the project directory, a ``null`` value +If the given file path is out of the project directory, a ``null`` value will be returned. .. _reference-twig-tags: From 540817e5c815620f3efaf9930f5a34003a389899 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Wed, 25 Jul 2018 09:40:31 +0200 Subject: [PATCH 3/3] Final reword --- reference/twig_reference.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index 817835b1fa2..d3f87af2a8a 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -650,7 +650,7 @@ file_relative ``file`` **type**: ``string`` -It transforms the given absolute file path into a relative file path from the +It transforms the given absolute file path into a new file path relative to project's root directory: .. code-block:: twig