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 00abe12

Browse filesBrowse files
committed
Improved TwigExtension to show default values and optional arguments
1 parent 60a10e8 commit 00abe12
Copy full SHA for 00abe12

File tree

Expand file treeCollapse file tree

1 file changed

+67
-66
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+67
-66
lines changed

‎reference/twig_reference.rst

Copy file name to clipboardExpand all lines: reference/twig_reference.rst
+67-66Lines changed: 67 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ render
3030

3131
.. code-block:: twig
3232
33-
{{ render(uri, options) }}
33+
{{ render(uri, options = []) }}
3434
3535
``uri``
3636
**type**: ``string`` | ``ControllerReference``
37-
``options``
37+
``options`` *(optional)*
3838
**type**: ``array`` **default**: ``[]``
3939

4040
Renders the fragment for the given controller (using the `controller`_ function)
@@ -53,11 +53,11 @@ render_esi
5353

5454
.. code-block:: twig
5555
56-
{{ render_esi(uri, options) }}
56+
{{ render_esi(uri, options = []) }}
5757
5858
``uri``
5959
**type**: ``string`` | ``ControllerReference``
60-
``options``
60+
``options`` *(optional)*
6161
**type**: ``array`` **default**: ``[]``
6262

6363
Generates an ESI tag when possible or falls back to the behavior of
@@ -80,13 +80,13 @@ controller
8080

8181
.. code-block:: twig
8282
83-
{{ controller(controller, attributes, query) }}
83+
{{ controller(controller, attributes = [], query = []) }}
8484
8585
``controller``
8686
**type**: ``string``
87-
``attributes``
87+
``attributes`` *(optional)*
8888
**type**: ``array`` **default**: ``[]``
89-
``query``
89+
``query`` *(optional)*
9090
**type**: ``array`` **default**: ``[]``
9191

9292
Returns an instance of ``ControllerReference`` to be used with functions
@@ -98,11 +98,11 @@ asset
9898

9999
.. code-block:: twig
100100
101-
{{ asset(path, packageName, absolute = false, version = null) }}
101+
{{ asset(path, packageName = null, absolute = false, version = null) }}
102102
103103
``path``
104104
**type**: ``string``
105-
``packageName``
105+
``packageName`` *(optional)*
106106
**type**: ``string`` | ``null`` **default**: ``null``
107107
``absolute`` (deprecated as of 2.7)
108108
**type**: ``boolean`` **default**: ``false``
@@ -118,9 +118,9 @@ assets_version
118118

119119
.. code-block:: twig
120120
121-
{{ assets_version(packageName) }}
121+
{{ assets_version(packageName = null) }}
122122
123-
``packageName``
123+
``packageName`` *(optional)*
124124
**type**: ``string`` | ``null`` **default**: ``null``
125125

126126
Returns the current version of the package, more information in
@@ -131,11 +131,11 @@ form
131131

132132
.. code-block:: twig
133133
134-
{{ form(view, variables) }}
134+
{{ form(view, variables = []) }}
135135
136136
``view``
137137
**type**: ``FormView``
138-
``variables``
138+
``variables`` *(optional)*
139139
**type**: ``array`` **default**: ``[]``
140140

141141
Renders the HTML of a complete form, more information in
@@ -146,11 +146,11 @@ form_start
146146

147147
.. code-block:: twig
148148
149-
{{ form_start(view, variables) }}
149+
{{ form_start(view, variables = []) }}
150150
151151
``view``
152152
**type**: ``FormView``
153-
``variables``
153+
``variables`` *(optional)*
154154
**type**: ``array`` **default**: ``[]``
155155

156156
Renders the HTML start tag of a form, more information in
@@ -161,11 +161,11 @@ form_end
161161

162162
.. code-block:: twig
163163
164-
{{ form_end(view, variables) }}
164+
{{ form_end(view, variables = []) }}
165165
166166
``view``
167167
**type**: ``FormView``
168-
``variables``
168+
``variables`` *(optional)*
169169
**type**: ``array`` **default**: ``[]``
170170

171171
Renders the HTML end tag of a form together with all fields that have not
@@ -191,11 +191,11 @@ form_widget
191191

192192
.. code-block:: twig
193193
194-
{{ form_widget(view, variables) }}
194+
{{ form_widget(view, variables = []) }}
195195
196196
``view``
197197
**type**: ``FormView``
198-
``variables``
198+
``variables`` *(optional)*
199199
**type**: ``array`` **default**: ``[]``
200200

201201
Renders a complete form or a specific HTML widget of a field, more information
@@ -219,13 +219,13 @@ form_label
219219

220220
.. code-block:: twig
221221
222-
{{ form_label(view, label, variables) }}
222+
{{ form_label(view, label = null, variables = []) }}
223223
224224
``view``
225225
**type**: ``FormView``
226-
``label``
226+
``label`` *(optional)*
227227
**type**: ``string`` **default**: ``null``
228-
``variables``
228+
``variables`` *(optional)*
229229
**type**: ``array`` **default**: ``[]``
230230

231231
Renders the label for the given field, more information in
@@ -236,11 +236,11 @@ form_row
236236

237237
.. code-block:: twig
238238
239-
{{ form_row(view, variables) }}
239+
{{ form_row(view, variables = []) }}
240240
241241
``view``
242242
**type**: ``FormView``
243-
``variables``
243+
``variables`` *(optional)*
244244
**type**: ``array`` **default**: ``[]``
245245

246246
Renders the row (the field's label, errors and widget) of the given field,
@@ -251,11 +251,11 @@ form_rest
251251

252252
.. code-block:: twig
253253
254-
{{ form_rest(view, variables) }}
254+
{{ form_rest(view, variables = []) }}
255255
256256
``view``
257257
**type**: ``FormView``
258-
``variables``
258+
``variables`` *(optional)*
259259
**type**: ``array`` **default**: ``[]``
260260

261261
Renders all fields that have not yet been rendered, more information in
@@ -279,13 +279,13 @@ is_granted
279279

280280
.. code-block:: twig
281281
282-
{{ is_granted(role, object, field) }}
282+
{{ is_granted(role, object = null, field = null) }}
283283
284284
``role``
285285
**type**: ``string``
286-
``object``
286+
``object`` *(optional)*
287287
**type**: ``object``
288-
``field``
288+
``field`` *(optional)*
289289
**type**: ``string``
290290

291291
Returns ``true`` if the current user has the required role. Optionally,
@@ -302,21 +302,22 @@ logout_path
302302

303303
.. code-block:: twig
304304
305-
{{ logout_path(key) }}
305+
{{ logout_path(key = null) }}
306306
307-
``key``
307+
``key`` *(optional)*
308308
**type**: ``string``
309309

310-
Generates a relative logout URL for the given firewall.
310+
Generates a relative logout URL for the given firewall. If no key is provided,
311+
the URL is generated for the current firewall the user is logged into.
311312

312313
logout_url
313314
~~~~~~~~~~
314315

315316
.. code-block:: twig
316317
317-
{{ logout_url(key) }}
318+
{{ logout_url(key = null) }}
318319
319-
``key``
320+
``key`` *(optional)*
320321
**type**: ``string``
321322

322323
Equal to the `logout_path`_ function, but it'll generate an absolute URL
@@ -327,13 +328,13 @@ path
327328

328329
.. code-block:: twig
329330
330-
{{ path(name, parameters, relative) }}
331+
{{ path(name, parameters = [], relative = false) }}
331332
332333
``name``
333334
**type**: ``string``
334-
``parameters``
335+
``parameters`` *(optional)*
335336
**type**: ``array`` **default**: ``[]``
336-
``relative``
337+
``relative`` *(optional)*
337338
**type**: ``boolean`` **default**: ``false``
338339

339340
Returns the relative URL (without the scheme and host) for the given route.
@@ -345,13 +346,13 @@ url
345346

346347
.. code-block:: twig
347348
348-
{{ url(name, parameters, schemeRelative) }}
349+
{{ url(name, parameters = [], schemeRelative = false) }}
349350
350351
``name``
351352
**type**: ``string``
352-
``parameters``
353+
``parameters`` *(optional)*
353354
**type**: ``array`` **default**: ``[]``
354-
``schemeRelative``
355+
``schemeRelative`` *(optional)*
355356
**type**: ``boolean`` **default**: ``false``
356357

357358
Returns the absolute URL (with scheme and host) for the given route. If
@@ -432,15 +433,15 @@ trans
432433

433434
.. code-block:: twig
434435
435-
{{ message|trans(arguments, domain, locale) }}
436+
{{ message|trans(arguments = [], domain = null, locale = null) }}
436437
437438
``message``
438439
**type**: ``string``
439-
``arguments``
440+
``arguments`` *(optional)*
440441
**type**: ``array`` **default**: ``[]``
441-
``domain``
442+
``domain`` *(optional)*
442443
**type**: ``string`` **default**: ``null``
443-
``locale``
444+
``locale`` *(optional)*
444445
**type**: ``string`` **default**: ``null``
445446

446447
Translates the text into the current language. More information in
@@ -451,17 +452,17 @@ transchoice
451452

452453
.. code-block:: twig
453454
454-
{{ message|transchoice(count, arguments, domain, locale) }}
455+
{{ message|transchoice(count, arguments = [], domain = null, locale = null) }}
455456
456457
``message``
457458
**type**: ``string``
458459
``count``
459460
**type**: ``integer``
460-
``arguments``
461+
``arguments`` *(optional)*
461462
**type**: ``array`` **default**: ``[]``
462-
``domain``
463+
``domain`` *(optional)*
463464
**type**: ``string`` **default**: ``null``
464-
``locale``
465+
``locale`` *(optional)*
465466
**type**: ``string`` **default**: ``null``
466467

467468
Translates the text with pluralization support. More information in
@@ -472,13 +473,13 @@ yaml_encode
472473

473474
.. code-block:: twig
474475
475-
{{ input|yaml_encode(inline, dumpObjects) }}
476+
{{ input|yaml_encode(inline = 0, dumpObjects = false) }}
476477
477478
``input``
478479
**type**: ``mixed``
479-
``inline``
480+
``inline`` *(optional)*
480481
**type**: ``integer`` **default**: ``0``
481-
``dumpObjects``
482+
``dumpObjects`` *(optional)*
482483
**type**: ``boolean`` **default**: ``false``
483484

484485
Transforms the input into YAML syntax. See :ref:`components-yaml-dump` for
@@ -489,13 +490,13 @@ yaml_dump
489490

490491
.. code-block:: twig
491492
492-
{{ value|yaml_dump(inline, dumpObjects) }}
493+
{{ value|yaml_dump(inline = 0, dumpObjects = false) }}
493494
494495
``value``
495496
**type**: ``mixed``
496-
``inline``
497+
``inline`` *(optional)*
497498
**type**: ``integer`` **default**: ``0``
498-
``dumpObjects``
499+
``dumpObjects`` *(optional)*
499500
**type**: ``boolean`` **default**: ``false``
500501

501502
Does the same as `yaml_encode() <yaml_encode>`_, but includes the type in
@@ -557,11 +558,11 @@ file_excerpt
557558

558559
.. code-block:: twig
559560
560-
{{ file|file_excerpt(line) }}
561+
{{ file|file_excerpt(line = null) }}
561562
562563
``file``
563564
**type**: ``string``
564-
``line``
565+
``line`` *(optional)*
565566
**type**: ``integer``
566567

567568
Generates an excerpt of seven lines around the given ``line``.
@@ -571,13 +572,13 @@ format_file
571572

572573
.. code-block:: twig
573574
574-
{{ file|format_file(line, text) }}
575+
{{ file|format_file(line, text = null) }}
575576
576577
``file``
577578
**type**: ``string``
578579
``line``
579580
**type**: ``integer``
580-
``text``
581+
``text`` *(optional)*
581582
**type**: ``string`` **default**: ``null``
582583

583584
Generates the file path inside an ``<a>`` element. If the path is inside
@@ -601,9 +602,9 @@ file_link
601602

602603
.. code-block:: twig
603604
604-
{{ file|file_link(line) }}
605+
{{ file|file_link(line = null) }}
605606
606-
``line``
607+
``line`` *(optional)*
607608
**type**: ``integer``
608609

609610
Generates a link to the provided file (and optionally line number) using
@@ -637,11 +638,11 @@ trans
637638
638639
{% trans with vars from domain into locale %}{% endtrans %}
639640
640-
``vars``
641+
``vars`` *(optional)*
641642
**type**: ``array`` **default**: ``[]``
642-
``domain``
643+
``domain`` *(optional)*
643644
**type**: ``string`` **default**: ``string``
644-
``locale``
645+
``locale`` *(optional)*
645646
**type**: ``string`` **default**: ``string``
646647

647648
Renders the translation of the content. More information in :ref:`book-translation-tags`.
@@ -655,11 +656,11 @@ transchoice
655656
656657
``count``
657658
**type**: ``integer``
658-
``vars``
659+
``vars`` *(optional)*
659660
**type**: ``array`` **default**: ``[]``
660-
``domain``
661+
``domain`` *(optional)*
661662
**type**: ``string`` **default**: ``null``
662-
``locale``
663+
``locale`` *(optional)*
663664
**type**: ``string`` **default**: ``null``
664665

665666
Renders the translation of the content with pluralization support, more

0 commit comments

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