@@ -81,6 +81,35 @@ Generates the URI of :ref:`a fragment <fragments-path-config>`.
81
81
.. versionadded :: 5.3
82
82
83
83
The ``fragment_uri() `` function was introduced in Symfony 5.3.
84
+ Example 1
85
+
86
+ .. code-block :: twig
87
+
88
+ {{ fragment_uri(controller('App\\Controller\\HomeController::index'),
89
+ absolute = true, strict = true, sign = true) }}
90
+
91
+ Output:
92
+
93
+ .. code-block :: html
94
+
95
+ <a href =" https://example.com/_fragment?_path=_controller=App%5CController%5CHomeController%3A%3Aindex& _hash=abcdef123456" >
96
+ https://example.com/_fragment?_path=_controller=App%5CController%5CHomeController%3A%3Aindex& _hash=abcdef123456
97
+ </a >
98
+
99
+ Example 2
100
+
101
+ .. code-block :: twig
102
+
103
+ {{ fragment_uri(controller('App\\Controller\\UserController::profile',
104
+ { 'id': 42 }), absolute = false, strict = false, sign = false) }}
105
+
106
+ Output:
107
+
108
+ .. code-block :: html
109
+
110
+ <a href =" /_fragment?_path=_controller=App%5CController%5CUserController%3A%3Aprofile&id=42" >
111
+ /_fragment?_path=_controller=App%5CController%5CUserController%3A%3Aprofile&id=42
112
+ </a >
84
113
85
114
controller
86
115
~~~~~~~~~~
@@ -102,6 +131,21 @@ like :ref:`render() <reference-twig-function-render>` and
102
131
103
132
.. _reference-twig-function-asset :
104
133
134
+ .. code-block :: twig
135
+
136
+ {% set myArray = {'a': 'foo', 'b': 'bar'} %}
137
+
138
+ <iframe src="{{ render(controller('App\\Controller\\MyController::baz', {'myArray': myArray})) }}"></iframe>
139
+
140
+ Output:
141
+
142
+ .. code-block :: html
143
+
144
+ <iframe src =" <ul>
145
+ <li>foo</li>
146
+ <li>bar</li>
147
+ </ul>" ></iframe >
148
+
105
149
asset
106
150
~~~~~
107
151
@@ -157,6 +201,11 @@ csrf_token
157
201
Renders a CSRF token. Use this function if you want :doc: `CSRF protection </security/csrf >`
158
202
in a regular HTML form not managed by the Symfony Form component.
159
203
204
+ .. code-block :: twig
205
+
206
+ {{ csrf_token(intention = 'my_form') }}
207
+ {# output: generates a variable token #}
208
+
160
209
is_granted
161
210
~~~~~~~~~~
162
211
@@ -532,6 +581,28 @@ Generates an excerpt of a code file around the given ``line`` number. The
532
581
``srcContext `` argument defines the total number of lines to display around the
533
582
given line number (use ``-1 `` to display the whole file).
534
583
584
+ Let's assume this is the content of a file :
585
+
586
+ .. code-block :: text
587
+
588
+ a
589
+ b
590
+ c
591
+ d
592
+ e
593
+
594
+ .. code-block :: twig
595
+
596
+ {{ "/path/to/file/file.txt"|file_excerpt(line = 4, srcContext = 1) }}
597
+ {# output:
598
+ 3.c
599
+ 4.d
600
+ 5.e #}
601
+
602
+ {{ "/path/to/file/file.txt"|file_excerpt(line = 1, srcContext = 0) }}
603
+ {# output:
604
+ 1.a #}
605
+
535
606
format_file
536
607
~~~~~~~~~~~
537
608
@@ -550,6 +621,36 @@ Generates the file path inside an ``<a>`` element. If the path is inside
550
621
the kernel root directory, the kernel root directory path is replaced by
551
622
``kernel.project_dir `` (showing the full path in a tooltip on hover).
552
623
624
+ Example 1
625
+
626
+ .. code-block :: twig
627
+
628
+ {{ "path/to/file/file.txt"|format_file(line = 1, text = "my_text") }}
629
+
630
+ Output:
631
+
632
+ .. code-block :: html
633
+
634
+ <a href =" path/to/file/file.txt#L1"
635
+ title =" Click to open this file" class =" file_link" >my_text at line 1
636
+ </a >
637
+
638
+ Example 2
639
+
640
+ .. code-block :: twig
641
+
642
+ {{ "path/to/file/file.txt"|format_file(line = 3) }}
643
+
644
+ Output:
645
+
646
+ .. code-block :: html
647
+
648
+ <a href =" path/to/file/file.txt#L3"
649
+ title =" Click to open this file" class =" file_link" >
650
+ <abbr title =" path/to/file/file.txt" >file.txt</abbr >
651
+ / at line 3
652
+ </a >
653
+
553
654
format_file_from_text
554
655
~~~~~~~~~~~~~~~~~~~~~
555
656
0 commit comments