Skip to content
Nat! edited this page Mar 1, 2023 · 3 revisions

filter pushes the resultant text of template texts and expressions through a NSString method returning a string. A filter has a corresponding endfilter to turn off filtering.

Example 1

{% filter lowercaseString|capitalizedString %}
This is filtered and pushed through lowercaseString and then capitalizedString.
{% filter uppercaseString %}
Witness how this string not all uppercased, because the filter pipes add up with
nesting.
   {% endfilter %}
back to original.
{% endfilter %}

Output:

This Is Filtered And Pushed Through Lowercasestring And Then Capitalizedstring.
Witness How This String Not All Uppercased, Because The Filter Pipes Add Up With
nesting.
Back To Original.

Example 2

{% filter lowercaseString| [[self componentsSeparatedByString:@"/"] componentsJoinedByString:@"-"] %}
THIS/IS/POSSIBLE
{% endfilter %}

Output:

THIS-IS-POSSIBLE

There is also function filter() available. This will push a string argument through the currently active filter only (but not through the chain). If the filter ist stateful (like MulleMarkdown), this may not produce an immediate result.

Example 3

{% filter uppercaseString %}
{% lower=@"lower"
   upper = filter( lower) %}
{% endfilter %}
{{ lower }} becomes {{ upper }}

Output:

lower becomes LOWER

You can give filter an array of keywords output and/or plaintext to tell it what to filter. The default is both.

Example 4

{% filter uppercaseString, (output) %}
This won't get filtered, but {{ "this" }}. Convenient to wrap around HTML
code for example and setting the filter to htmlEscapedString.
{% endfilter %}

Output:

This won't get filtered, but THIS. Convenient to wrap around HTML
code for example and setting the filter to htmlEscapedString.
Clone this wiki locally