Skip to content

Commit 3eec2ce

Browse files
committed
Document file_relative Twig function
1 parent c88ca04 commit 3eec2ce

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

reference/twig_reference.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,27 @@ 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+
.. code-block:: twig
644+
645+
{{ file|file_relative }}
646+
647+
``file``
648+
**type**: ``string``
649+
650+
Returns the relative path from the passed absolute file path. For example,
651+
assume you've a project in the following directory: ``/var/www/blog/``.
652+
653+
.. code-block:: twig
654+
655+
{{ '/var/www/blog/templates/admin/index.html.twig'|file_relative }}
656+
{# templates/admin/index.html.twig #}
657+
658+
If the passed path doesn't match the project directory, a ``null`` value
659+
will be returned.
660+
640661
.. _reference-twig-tags:
641662

642663
Tags

0 commit comments

Comments
 (0)