@@ -96,6 +96,11 @@ Returns an instance of ``ControllerReference`` to be used with functions
9696like :ref: `render() <reference-twig-function-render >` and
9797:ref: `render_esi() <reference-twig-function-render-esi >`.
9898
99+ .. code-block :: html+twig
100+
101+ {{ render(controller('App\\ Controller\\ BlogController:latest', {max: 3})) }}
102+ {# output: the content returned by the controller method; e.g. a rendered Twig template #}
103+
99104.. _reference-twig-function-asset :
100105
101106asset
@@ -171,6 +176,12 @@ csrf_token
171176Renders a CSRF token. Use this function if you want :doc: `CSRF protection </security/csrf >`
172177in a regular HTML form not managed by the Symfony Form component.
173178
179+ .. code-block :: twig
180+
181+ {{ csrf_token('my_form') }}
182+ {# output: a random alphanumeric string like:
183+ a.YOosAd0fhT7BEuUCFbROzrvgkW8kpEmBDQ_DKRMUi2o.Va8ZQKt5_2qoa7dLW-02_PLYwDBx9nnWOluUHUFCwC5Zo0VuuVfQCqtngg #}
184+
174185 is_granted
175186~~~~~~~~~~
176187
@@ -840,6 +851,34 @@ Generates an excerpt of a code file around the given ``line`` number. The
840851``srcContext `` argument defines the total number of lines to display around the
841852given line number (use ``-1 `` to display the whole file).
842853
854+ Consider the following as the content of ``file.txt ``:
855+
856+ .. code-block :: text
857+
858+ a
859+ b
860+ c
861+ d
862+ e
863+
864+ .. code-block :: twig
865+
866+ {{ '/path/to/file.txt'|file_excerpt(line = 4, srcContext = 1) }}
867+ {# output:
868+ <ol start="3">
869+ <li><a class="anchor" id="line3"></a><code>c</code></li>
870+ <li class="selected"><a class="anchor" id="line4"></a><code>d</code></li>
871+ <li><a class="anchor" id="line5"></a><code>e</code></li>
872+ </ol>
873+ #}
874+
875+ {{ '/path/to/file.txt'|file_excerpt(line = 1, srcContext = 0) }}
876+ {# output:
877+ <ol start="1">
878+ <li class="selected"><a class="anchor" id="line1"></a><code>a</code></li>
879+ </ol>
880+ #}
881+
843882 format_file
844883~~~~~~~~~~~
845884
@@ -858,6 +897,29 @@ Generates the file path inside an ``<a>`` element. If the path is inside
858897the kernel root directory, the kernel root directory path is replaced by
859898``kernel.project_dir `` (showing the full path in a tooltip on hover).
860899
900+ .. code-block :: twig
901+
902+ {{ '/path/to/file.txt'|format_file(line = 1, text = "my_text") }}
903+ {# output:
904+ <a href="/path/to/file.txt#L1"
905+ title="Click to open this file" class="file_link">my_text at line 1
906+ </a>
907+ #}
908+
909+ {{ "/path/to/file.txt"|format_file(line = 3) }}
910+ {# output:
911+ <a href="/path/to/file.txt&line=3"
912+ title="Click to open this file" class="file_link">/path/to/file.txt at line 3
913+ </a>
914+ #}
915+
916+ .. tip ::
917+
918+ If you set the :ref: `framework.ide <reference-framework-ide >` option, the
919+ generated links will change to open the file in that IDE/editor. For example,
920+ when using PhpStorm, the ``<a href="/path/to/file.txt&line=3" `` link will
921+ become ``<a href="phpstorm://open?file=/path/to/file.txt&line=3" ``.
922+
861923format_file_from_text
862924~~~~~~~~~~~~~~~~~~~~~
863925
0 commit comments