Skip to content

Tags Argument

Q edited this page Dec 13, 2020 · 4 revisions

Willow Argument Tags are commonly used to passed configuration options to Willow Tags and have the following format:

{+ arguments +}

Willows can be run without passing arguments, if they collect their configuration from a file, but it is often necessary to pass additional configuration, or, for example to enable debugging via inline arguments - here is an example:

<div class='col-12'>Escaped Value is -> <strong>{~ ui~escaped {+
	[array] markup = 
		template: "{{ [esc_html] escaped }}"
+} ~}</strong></div>

This Willow calls the ui->escaped() class method and passes the markup->template to wrap around the returned data value - while also defining that the value of the escaped key should be escaped - via the [e] escape flag.

Markup

Willow will render returned data values without any markup, however, it is important to note that the default {{ variable }} template will only with a single data->value and is assigned to match the task name.

In both examples, we presume that Willow is returned "good" data, in the format of an array with a single key matching the willow->task name which has a value of "This Worked", like such:

array(
    'example' => 'This Worked'
)

Here are a few examples to demonstrate how this works:

{~ ui~example ~} will render This Worked

{~ ui~example {+ {{ example }} +} ~} will also render This Worked

{~ ui~example {+ <div>{{ example }}</div> +} ~} will render <div>This Worked</div>

<div class='col-12'>Somehow, <strong>{~ ui~example {+
	[array] markup = 
		template: "{{ example }}"
+} ~}</strong> too :)</div>

will render <div class='col-12'>Somehow, <strong>This Worked</strong> too :)</div>

{~ ui~example {+ {{ bad }} +} ~} will render nothing, as the variable key name does not match

The names of the keys in the returned array determine the variable name to define in the templates for rendering, take the following returned array example:

array(
    'one' => 'I am one',
    'two' => 'I am two',
    'three' => 'I am too.. or three?'
)

This would make available 3 variables within the scope of the current Willow one, two and three

Configuration

It is also possible to pass simple or complete configuration options from a Willow to the connected class::method, take the following complex example:

{~ group~user_dashboard_featured {+ [array] config = post: {% [return] w__post_id_by_slug{+ dashboard +} %} +} ~}

This Willow calls the group context and ask ACF to return data from the field group user_dashboard_featured, while also passing an array of configuration data, including the return value of a PHP Function.

It is possible to pass complex configuration options, but the caveat should be that this comes at the cost of readability, and as we want to provide a tool that is comfortable for UI Developers, it would be good to limit the complexity of passed configuration, where possible.

Clone this wiki locally