@@ -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
@@ -818,6 +829,34 @@ Generates an excerpt of a code file around the given ``line`` number. The
818829``srcContext `` argument defines the total number of lines to display around the
819830given line number (use ``-1 `` to display the whole file).
820831
832+ Consider the following as the content of ``file.txt ``:
833+
834+ .. code-block :: text
835+
836+ a
837+ b
838+ c
839+ d
840+ e
841+
842+ .. code-block :: twig
843+
844+ {{ '/path/to/file.txt'|file_excerpt(line = 4, srcContext = 1) }}
845+ {# output:
846+ <ol start="3">
847+ <li><a class="anchor" id="line3"></a><code>c</code></li>
848+ <li class="selected"><a class="anchor" id="line4"></a><code>d</code></li>
849+ <li><a class="anchor" id="line5"></a><code>e</code></li>
850+ </ol>
851+ #}
852+
853+ {{ '/path/to/file.txt'|file_excerpt(line = 1, srcContext = 0) }}
854+ {# output:
855+ <ol start="1">
856+ <li class="selected"><a class="anchor" id="line1"></a><code>a</code></li>
857+ </ol>
858+ #}
859+
821860 format_file
822861~~~~~~~~~~~
823862
@@ -836,6 +875,29 @@ Generates the file path inside an ``<a>`` element. If the path is inside
836875the kernel root directory, the kernel root directory path is replaced by
837876``kernel.project_dir `` (showing the full path in a tooltip on hover).
838877
878+ .. code-block :: twig
879+
880+ {{ '/path/to/file.txt'|format_file(line = 1, text = "my_text") }}
881+ {# output:
882+ <a href="/path/to/file.txt#L1"
883+ title="Click to open this file" class="file_link">my_text at line 1
884+ </a>
885+ #}
886+
887+ {{ "/path/to/file.txt"|format_file(line = 3) }}
888+ {# output:
889+ <a href="/path/to/file.txt&line=3"
890+ title="Click to open this file" class="file_link">/path/to/file.txt at line 3
891+ </a>
892+ #}
893+
894+ .. tip ::
895+
896+ If you set the :ref: `framework.ide <reference-framework-ide >` option, the
897+ generated links will change to open the file in that IDE/editor. For example,
898+ when using PhpStorm, the ``<a href="/path/to/file.txt&line=3" `` link will
899+ become ``<a href="phpstorm://open?file=/path/to/file.txt&line=3" ``.
900+
839901format_file_from_text
840902~~~~~~~~~~~~~~~~~~~~~
841903
0 commit comments