-
Notifications
You must be signed in to change notification settings - Fork 1
Tags Flag
Technically, flags are not tags, they are filters, which tell Willow how the data should be retrieved, formatted and displayed.
Currently, Willow only supports 6 flags:
- array -> indicates that configuration is passed in an array format
- buffer -> tells Willow to attempt to buffer the function response data
- return -> return data in place of original tag, mostly used with {% PHP_function %} tags
- debug -> used to enable debugging for one specific Willow {~ class~method ~}
- html -> used in comment tags to display an html comment
- php -> used in comment tags to write a php comment
Flags are identified by placing a single letter, or group of single letters inside a matching pair of square brackets, the following examples show some of the possible placements and what effect they have:
The example below is the most common usage of flags - using the [a] Array flat to pass a string of configuration options to the defined Willow - also note the use of the [r] flag to pre-build data for the Willow query.
{~ group~frontpage_work {+ [array] config->post = {% [r] get_site_option{+ page_on_front +} %} +} ~}
This example shows the [r] return flag being used to directly replace markup before Willows are run ( as flags are passed first )
<a href="{% [return] get_site_url %}" title="{% [return] get_bloginfo{+ "name" +} %}">
{% [return] get_bloginfo{+ "name" +} %}
</a>
This can be useful where you cannot control the process of the function being called, but not recommended, note that the flag is on the willow tag, not the variable:
{~ [buffer] ui~needs_buffering {+ <div>{{ variable }}</div> +} ~}
Flags and Filters are connected concepts and use the same tag - [ filter ].
However, filters are run after Willows are parsed, once the controllers have returned data and Willows have been compiled into HTML, they are used to post-process the data by changing format - here are some examples:
{~ ui~example {+ <div>{{ [ esc_html ] needs-escaping }}</div> +} ~}
{~ ui~example {+ <div>{{ [ strip_tags ] needs-escaping }}</div> +} ~}
{~ ui~example {+ <div>{{ [ esc_html, strip_tags ] needs-escaping-and-stripping }}</div> +} ~}
Note that escaping uses both mb_convert_encoding
& htmlentities
set to ENT_QUOTES
- both use UTF-8
encoding
{~ [ escape:html ] ui~escape {+ <div>{{ variable }}</div> +} ~}
<div class='col-12'>Escaped Value is -> <strong>{~ ui~escaped {+
[a] markup =
template: "{{ [ esc_html ] escaped }}"
+} ~}</strong></div>
- Filters are collected as data is buffered in and applied before tags are replaced with data.
- Filters can be extended via the
q/willow/filters
WordPress filter, which is run once when the first variable is filtered. - Variables are filtered first, then then entire tag is filtered by any global filters defined.