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 82fea87

Browse filesBrowse files
edgarbntjaviereguiluz
authored andcommitted
[Twig] [twig reference] add examples to functions (format_file, file_…
1 parent f187ace commit 82fea87
Copy full SHA for 82fea87

File tree

Expand file treeCollapse file tree

1 file changed

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

1 file changed

+72
-0
lines changed

‎reference/twig_reference.rst

Copy file name to clipboardExpand all lines: reference/twig_reference.rst
+72Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,21 @@ like :ref:`render() <reference-twig-function-render>` and
9898

9999
.. _reference-twig-function-asset:
100100

101+
.. code-block:: html+twig
102+
103+
{% set myArray = {'a': 'foo', 'b': 'bar'} %}
104+
105+
<iframe src="{{ render(controller('App\\Controller\\MyController::baz', {'myArray': myArray})) }}"></iframe>
106+
107+
Output:
108+
109+
.. code-block:: html
110+
111+
<iframe src="<ul>
112+
<li>foo</li>
113+
<li>bar</li>
114+
</ul>"></iframe>
115+
101116
asset
102117
~~~~~
103118

@@ -171,6 +186,11 @@ csrf_token
171186
Renders a CSRF token. Use this function if you want :doc:`CSRF protection </security/csrf>`
172187
in a regular HTML form not managed by the Symfony Form component.
173188

189+
.. code-block:: twig
190+
191+
{{ csrf_token(intention = 'my_form') }}
192+
{# output: generates a variable token #}
193+
174194
is_granted
175195
~~~~~~~~~~
176196

@@ -830,6 +850,28 @@ Generates an excerpt of a code file around the given ``line`` number. The
830850
``srcContext`` argument defines the total number of lines to display around the
831851
given line number (use ``-1`` to display the whole file).
832852

853+
Let's assume this is the content of a file :
854+
855+
.. code-block:: text
856+
857+
a
858+
b
859+
c
860+
d
861+
e
862+
863+
.. code-block:: twig
864+
865+
{{ "/path/to/file/file.txt"|file_excerpt(line = 4, srcContext = 1) }}
866+
{# output:
867+
3.c
868+
4.d
869+
5.e #}
870+
871+
{{ "/path/to/file/file.txt"|file_excerpt(line = 1, srcContext = 0) }}
872+
{# output:
873+
1.a #}
874+
833875
format_file
834876
~~~~~~~~~~~
835877

@@ -848,6 +890,36 @@ Generates the file path inside an ``<a>`` element. If the path is inside
848890
the kernel root directory, the kernel root directory path is replaced by
849891
``kernel.project_dir`` (showing the full path in a tooltip on hover).
850892

893+
Example 1
894+
895+
.. code-block:: twig
896+
897+
{{ "path/to/file/file.txt"|format_file(line = 1, text = "my_text") }}
898+
899+
Output:
900+
901+
.. code-block:: html
902+
903+
<a href="path/to/file/file.txt#L1"
904+
title="Click to open this file" class="file_link">my_text at line 1
905+
</a>
906+
907+
Example 2
908+
909+
.. code-block:: twig
910+
911+
{{ "path/to/file/file.txt"|format_file(line = 3) }}
912+
913+
Output:
914+
915+
.. code-block:: html
916+
917+
<a href="path/to/file/file.txt#L3"
918+
title="Click to open this file" class="file_link">
919+
<abbr title="path/to/file/file.txt">file.txt</abbr>
920+
/ at line 3
921+
</a>
922+
851923
format_file_from_text
852924
~~~~~~~~~~~~~~~~~~~~~
853925

0 commit comments

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