Skip to content

Commit 364534b

Browse files
committed
minor #10115 Add file_relative function to the Twig reference (yceruto, javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Add file_relative function to the Twig reference Documenting https://github.com/symfony/symfony/pull/27978/files#diff-f1a4cceb03e213bc53ab3f0ed53b7da5R215 Commits ------- 540817e Final reword 67460dc Reword and added the versionadded directive 3eec2ce Document file_relative Twig function
2 parents f8da309 + 540817e commit 364534b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

reference/twig_reference.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,30 @@ file_link
637637
Generates a link to the provided file and line number using
638638
a preconfigured scheme.
639639

640+
file_relative
641+
~~~~~~~~~~~~~
642+
643+
.. versionadded::
644+
The ``file_relative`` filter was introduced in Symfony 4.2.
645+
646+
.. code-block:: twig
647+
648+
{{ file|file_relative }}
649+
650+
``file``
651+
**type**: ``string``
652+
653+
It transforms the given absolute file path into a new file path relative to
654+
project's root directory:
655+
656+
.. code-block:: twig
657+
658+
{{ '/var/www/blog/templates/admin/index.html.twig'|file_relative }}
659+
{# if project root dir is '/var/www/blog/', it returns 'templates/admin/index.html.twig' #}
660+
661+
If the given file path is out of the project directory, a ``null`` value
662+
will be returned.
663+
640664
.. _reference-twig-tags:
641665

642666
Tags

0 commit comments

Comments
 (0)