@@ -98,6 +98,21 @@ like :ref:`render() <reference-twig-function-render>` and
98
98
99
99
.. _reference-twig-function-asset :
100
100
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
+
101
116
asset
102
117
~~~~~
103
118
@@ -171,6 +186,11 @@ csrf_token
171
186
Renders a CSRF token. Use this function if you want :doc: `CSRF protection </security/csrf >`
172
187
in a regular HTML form not managed by the Symfony Form component.
173
188
189
+ .. code-block :: twig
190
+
191
+ {{ csrf_token(intention = 'my_form') }}
192
+ {# output: generates a variable token #}
193
+
174
194
is_granted
175
195
~~~~~~~~~~
176
196
@@ -830,6 +850,28 @@ Generates an excerpt of a code file around the given ``line`` number. The
830
850
``srcContext `` argument defines the total number of lines to display around the
831
851
given line number (use ``-1 `` to display the whole file).
832
852
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
+
833
875
format_file
834
876
~~~~~~~~~~~
835
877
@@ -848,6 +890,36 @@ Generates the file path inside an ``<a>`` element. If the path is inside
848
890
the kernel root directory, the kernel root directory path is replaced by
849
891
``kernel.project_dir `` (showing the full path in a tooltip on hover).
850
892
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
+
851
923
format_file_from_text
852
924
~~~~~~~~~~~~~~~~~~~~~
853
925
0 commit comments