Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 2.29 KB

tag-call.md

File metadata and controls

65 lines (46 loc) · 2.29 KB

Tag: "Call"

This tag calls a macro previously defined using the macro tag.

Node Information

Name Description
Tag Name call
End Tag N/A
Rendering Immediately; output is the rendering of the called macro block
Parameter Description
Block Name The name of the block you want to invoke.
... A variable list of arguments, must match block definition

Example: {% call myBlock "Dave" %}

When to use it

This node only works together with the macro tag. You must define a macro block first, using the macro tag, before you can call the define block using this call tag.

The number of arguments in a call invocation must match the number of parameters in a macro definition.

Note: In contrast to the set tag, the call and macro tags can be used for delayed execution of blocks. When the renderer encounters a macro block, it won't render it immediately, but instead it's contents are stored as a body of the block. When the renderer encounters a call tag, it will look up any matching block (by name), and will then invoke it using the context from the invocation point.

Do note that, due to the delayed invocation, a macro block can contain call tags that invoke the macro block again, thus allowing for scenarios such as recursion.

See the documentation for the macro tag for more information.

Usage example

{# define test1 #}
{% macro test1 %}
  Hello world! (inside test)
{% endmacro %}

{# define test2 #}
{% macro test2 a b c %}
  Received parameters in test2:
  - a = "{{a}}"
  - b = "{{b}}"
  - c = "{{c}}"

  // calling test1
  {% call test1 %}
{% endmacro %}

{# calling test2 #}
{% call test2 "hey" 123 "world"|capitalise %}

Will output:

  Received parameters in test2:
  - a = "hey"
  - b = "123"
  - c = "World"

  // calling test1
  Hello world! (inside test)