Input and Output Filters
What are Filters?
Filters in Revolution allow you to manipulate the way data is presented or parsed in a tag. They allow you to modify values from inside your templates.
Input Filters
Currently input filters process tag calls. More documentation to come.
Output Filters
In Revolution, Output Filters behave similarly to Phx calls in MODx Evolution - except they're built into the core. The syntax is like such:
[[element:modifier=`value`]]
They can also be chained (executed left to right):
[[element:modifier:anothermodifier=`value`:andanothermodifier:yetanother=`value2`]]
The list of string modifiers:
| Modifier |
Description |
Example |
|---|---|---|
| cat | Appends the options value (if not empty) to the input value | [[+numbooks:cat=` books`]] |
| lcase | Similar to PHP's strtolower |
[[+title:lcase]] |
| ucase | Similar to PHP's strtoupper |
[[+headline:ucase]] |
| ucfirst | Similar to PHP's ucfirst |
[[+name:ucfirst]] |
| htmlent | Similar to PHP's htmlentities. Uses the current value the system setting "modx_charset" |
[[+email:htmlent]] |
| esc,escape | Safely escapes character values |
[[+email:escape]] |
| strip | Replaces all linebreaks, tabs and multiple spaces with just one space |
[[+textdocument:strip]] |
| notags | Similar to PHP's strip_tags |
[[+code:strip_tags]] |
| len,length | Similar to PHP's strlen |
[[+longstring:strlen]] |
| reverse | Similar to PHP's strrev |
[[+mirrortext:reverse]] |
| wordwrap | Similar to PHP's wordwrap. Takes optional value to set wordwrap position. |
[[+bodytext:wordwrap=`80`]] |
| limit | Limits a string to a certain number of characters. Defaults to 100. |
[[+description:limit=`50`]] |
| ellipsis | Adds an ellipsis to and truncates a string if it's longer than a certain number of characters. Defaults to 100. |
[[+description:ellipsis=`50`]] |
| math | Returns the result of an advanced calculation (expensive on processor. not recommended) | |
| add,increment,incr | Returns input incremented by option (default: +1) | [[+downloads:incr]] [[+blackjack:add=`21`]] |
| subtract,decrement,decr | Returns input decremented by option (default: -1) | [[+countdown:decr]] [[+moneys:subtract=`100`]] |
| multiply,mpy | Returns input multiplied by option (default: *2) | [[+trifecta:mpy=`3`] |
| divide,div | Returns input divided by option (default: /2) Does not accept 0. |
[[+rating:div=`4`]] |
| modulus,mod | Returns the option modulus on input (default: %2, returns 0 or 1) | [[+number:mod]] |
| ifempty,default | Returns the input value if empty | [[+name:default=`anonymous`]] |
| nl2br | Similar to PHP's nl2br |
[[+textfile:nl2br]] |
| date | Similar to PHP's strftime. Value is format. |
[[+birthyear:date=`%Y`]] |
| strtotime |
Similar to PHP's strtotime. |
[[+thetime:strtotime]] |
| md5 | Similar to PHP's md5. |
[[+password:md5]] |
| userinfo | Returns the requested user data. The element must be a modUser ID. The value field is the column to grab. |
[[+userId:userinfo=`username`]] |
Examples
A good example of chaining would be to format a date string to another format, like so:
[[+mydate:strtotime:date=`%Y-%m-%d`]]
Directly accessing the modx_user_attributes table in the database using filters instead of a Snippet can be accomplished simply by utilizing the userinfo filter. Select the appropriate column from the table and link to it, like so:
User Internal Key: [[+userId:userinfo=`internalKey`]]<br />
User name: [[+userId:userinfo=`username`]]<br />
Full Name:[[+userId:userinfo=`fullname`]]<br />
Role: [[+userId:userinfo=`role`]]<br />
E-mail: [[++userId:userinfo=`email`]]<br />
Phone: [[+userId:userinfo=`phone`]]<br />
Mobile Phone: [[+userId:userinfo=`mobilephone`]]<br />
Fax: [[+userId:userinfo=`fax`]]<br />
Date of birth: [[+userId:userinfo=`dob`:date=`%Y-%m-%d`]]<br />
Gender[[+userId:userinfo=`gender`]]<br />
Country: [[+userId:userinfo=`country`]]<br />
State: [[+userId:userinfo=`state`]]<br />
Zip Code: [[+userId:userinfo=`zip`]]<br />
Photo: [[+userId:userinfo=`photo`]]<br />
Comment: [[+userId:userinfo=`comment`]]<br />
Password: [[+userId:userinfo=`password`]]<br />
Cache Password: [[+userId:userinfo=`cachepwd`]]<br />
Last Login: [[+userId:userinfo=`lastlogin`:date=`%Y-%m-%d`]]<br />
The Login:[[+userId:userinfo=`thislogin`:date=`%Y-%m-%d`]]<br />
Number of Logins: [[+userId:userinfo=`logincount`]]
Note that the user ID and username is already available by default in MODx, so you dont need to use the "userinfo" filter:
[[+modx.user.id]] - Prints the ID [[+modx.user.username]] - Prints the username |
Also, Snippets can be used as custom modifiers and filters. Simply put the Snippet name instead of the modifier. Example with a snippet named 'makeDownloadLink':
[[+file:makeDownloadLink=`notitle`]]
This will pass these properties to the snippet:
| Param | Value |
Example Result |
|---|---|---|
| input | The element's value. |
The value of [[+file]] |
| options | Any value passed to the modifier. |
'notitle' |
| token | The type of the parent element. |
+ (the token on `file`) |
| name | The name of the parent element. |
file |
| tag | The complete parent tag. |
[[+file:makeDownloadLink=`notitle`]] |
And then the return value of that call would be whatever the snippet returns.