mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 10:56:38 +00:00
document support for defining default argument values in the macro tag
This commit is contained in:
+9
-3
@@ -13,10 +13,16 @@ Here is a small example of a macro that renders a form element:
|
|||||||
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
|
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
Macros differ from native PHP functions in a few ways:
|
Default argument values can be defined with the ``default`` filter in the
|
||||||
|
macro body, as above, or as in native PHP functions:
|
||||||
|
|
||||||
* Default argument values are defined by using the ``default`` filter in the
|
.. code-block:: jinja
|
||||||
macro body;
|
|
||||||
|
{% macro input(name, value, type = 'text', size = 20) %}
|
||||||
|
<input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}" />
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
Macros differ from native PHP functions in a few ways:
|
||||||
|
|
||||||
* Arguments of a macro are always optional.
|
* Arguments of a macro are always optional.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user