File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -637,6 +637,30 @@ file_link
637
637
Generates a link to the provided file and line number using
638
638
a preconfigured scheme.
639
639
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
+
640
664
.. _reference-twig-tags :
641
665
642
666
Tags
You can’t perform that action at this time.
0 commit comments