Commit b5d92a6c authored by mxh's avatar mxh
Browse files

Issue #3276919 by mxh: Add a magic "filter" section variable

parent 405d6da8
Loading
Loading
Loading
Loading
+25 −7
Original line number Diff line number Diff line
@@ -231,13 +231,13 @@ a little bit more advanced checks. It has the following pattern:
Here are some examples:

```html
 * {{#if.node.title.empty}}Title is empty!{{/if.node.title.empty}}
 * {{^if.node.id.numeric}}ID is not numeric...{{/if.node.id.numeric}}
 * {{#if.user.uid.equals.1}}You are the admin.{{/if.user.uid.equals.1}}
 * {{#if.user.uid.greaterthan.1}}You are authenticated.{{/if.user.uid.greaterthan.1}}
 * {{#if.user.uid.lessthan.1}}You are anonymous.{{/if.user.uid.lessthan.1}}
 * {{#if.node.field_mytodolist.atleast.1}}You have work to do.{{/if.node.field_mytodolist.atleast.1}}
 * {{#if.node.field_mylazylist.atmost.0}}No time to be lazy.{{/if.node.field_mylazylist.atmost.1}}
{{#if.node.title.empty}}Title is empty!{{/if.node.title.empty}}
{{^if.node.id.numeric}}ID is not numeric...{{/if.node.id.numeric}}
{{#if.user.uid.equals.1}}You are the admin.{{/if.user.uid.equals.1}}
{{#if.user.uid.greaterthan.1}}You are authenticated.{{/if.user.uid.greaterthan.1}}
{{#if.user.uid.lessthan.1}}You are anonymous.{{/if.user.uid.lessthan.1}}
{{#if.node.field_mytodolist.atleast.1}}You have work to do.{{/if.node.field_mytodolist.atleast.1}}
{{#if.node.field_mylazylist.atmost.0}}No time to be lazy.{{/if.node.field_mylazylist.atmost.1}}
```

Conditions are possible on scalar values like numbers and strings. Lists are
@@ -443,6 +443,24 @@ within contextual filters, and then select "Provide a default value" ->
"Content ID from URL". For the reason why this is necessary, have a look at
https://www.drupal.org/project/mustache_templates/issues/3253881.

### 3.9 Filters

You can use the `{{#filter.<method>}}` section variable to apply a text
processing filter using a specified `<method>` on template contents.

Examples:

```html
{{#filter.trim}}  My whitespace will be trimmed.   {{/filter.trim}}
{{#filter.striptags}}<p>My HTML tags will be removed.</p>{{/filter.striptags}}
{{#filter.nl2br}}The new line \n will be converted to a break tag.{{/filter.nl2br}}
{{#filter.spaceless}}Removes whitespace between HTML tags.{{/filter.spaceless}}
{{#filter.upper}}Makes the whole text uppercase.{{/filter.upper}}
{{#filter.lower}}Makes the whole text lowercase.{{/filter.lower}}
{{#filter.capitalize}}The first letter of the text will be uppercase.{{/filter.capitalize}}
{{#filter.truncate.100}}This text will be truncated when it exceeds 100 characters, and appended with a ... if it was truncated.{{/filter.truncate.100}}
```

## 4. API

### 4.1 How Mustache templating works in Drupal