Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e3e4277

Browse filesBrowse files
committed
Merge branch '6.4' into 7.2
* 6.4: Tweaks and rewords [Twig] [twig reference] add examples to functions (format_file, file_…
2 parents d71855e + 3c4f753 commit e3e4277
Copy full SHA for e3e4277

File tree

Expand file treeCollapse file tree

2 files changed

+64
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+64
-0
lines changed

‎reference/configuration/framework.rst

Copy file name to clipboardExpand all lines: reference/configuration/framework.rst
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,8 @@ named ``kernel.http_method_override``.
19201920
$request = Request::createFromGlobals();
19211921
// ...
19221922

1923+
.. _reference-framework-ide:
1924+
19231925
ide
19241926
~~~
19251927

‎reference/twig_reference.rst

Copy file name to clipboardExpand all lines: reference/twig_reference.rst
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ Returns an instance of ``ControllerReference`` to be used with functions
9696
like :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

101106
asset
@@ -171,6 +176,12 @@ csrf_token
171176
Renders a CSRF token. Use this function if you want :doc:`CSRF protection </security/csrf>`
172177
in 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
819830
given 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
836875
the 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&amp;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&amp;line=3"`` link will
899+
become ``<a href="phpstorm://open?file=/path/to/file.txt&amp;line=3"``.
900+
839901
format_file_from_text
840902
~~~~~~~~~~~~~~~~~~~~~
841903

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.