Input and Output Filters (Output Modifiers)

Skip to end of metadata
Go to start of metadata


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 Filter

Currently the input filter processes tag calls in preparation for the output filter. It is generally used only internally by MODx.

Output Filter

In Revolution, the Output Filter applies one or more of series of output modifiers, which behave similarly to PHx calls in MODx Evolution - except they're built into the core. The syntax looks like this:

[[element:modifier=`value`]]

They can also be chained (executed left to right):

[[element:modifier:anothermodifier=`value`:andanothermodifier:yetanother=`value2`]]

You can also use these to modify Snippet output; note that the modifier comes after the Snippet name and before the question mark, e.g.

[[mySnippet:modifier=`value`? &mySnippetParam=`something`]]

Output Modifiers

The following table lists some of the existing modifiers and shows examples of their use. Although the examples below are placeholder tags, the output modifiers can be used with any MODx tag. Make sure that the placeholder used are actually receiving data.

Conditional output modifiers

Modifier Description Example
if, input    
or
Can be used to string output modifiers together with an "OR" relationship.
[[+numbooks:is=`5`:or:is=`6`:then=`There are 5 or 6 books!`:else=`Not sure how many books`]]
and
Can be used to string output modifiers together with an "AND" relationship.
 
isequalto, isequal, equalto, equals, is, eq
Compares to a passed value, and moves on if it's the same. Used with "then" and "else"
[[+numbooks:isequalto=`5`:then=`There are 5 books!`:else=`Not sure how many books`]]
notequalto, notequals, isnt, isnot, neq, ne
Compares to a passed value, and moves on if it is not the same. Used with "then" and "else"
[[+numbooks:notequalto=`5`:then=`Not sure how many books`:else=`There are 5 books!`]]
greaterthanorequalto, equalorgreaterthen, ge, eg, isgte, gte
Compares to a passed value, and moves on if it is greater than or equal to the value. Used with "then" and "else".
[[+numbooks:gte=`5`:then=`There are 5 books or more than 5 books`:else=`There are less than 5 books`]]
isgreaterthan, greaterthan, isgt, gt
Compares to a passed value, and moves on if it is greater than the value. Used with "then" and "else".
[[+numbooks:gt=`5`:then=`There are more than 5 books`:else=`There are less than 5 books`]]
equaltoorlessthan, lessthanorequalto, el, le, islte, lte
Compares to a passed value, and moves on if it is less then or equal to the value. Used with "then" and "else".
[[+numbooks:lte=`5`:then=`There are 5 or less than 5 books`:else=`There are more than 5 books`]]
islowerthan, islessthan, lowerthan, lessthan, islt, lt
Compares to a passed value, and moves on if it is less than the value. Used with "then" and "else". [[+numbooks:lte=`5`:then=`There are less than 5 books`:else=`There are more than 5 books`]]
hide
Will check earlier conditions, and hide the element if the conditions were met.
[[+numbooks:lt=`1`:hide]]
show
Will check earlier conditions, and show the element if the conditions were met.
[[+numbooks:gt=`0`:show]]
then
Conditional usage.
[[+numbooks:gt=`0`:then=`Now available!`]]
else
Conditional usage, together with then.
[[+numbooks:gt=`0`:then=`Now available!`:else=`Sorry, currently sold out.`]]
select
   
memberof, ismember, mo
Checks if the user is a member of the specified group(s).
[[+modx.user.id:memberof=`Administrator`]]

String output modifiers

Modifier Description Example
cat Appends the option's value (if not empty) to the input value [[+numbooks:cat=` books`]]
lcase, lowercase, strtolower Transforms strings to lowercase. Similar to PHP's strtolower  [[+title:lcase]]
ucase, uppercase, strtoupper Transforms strings to uppercase. Similar to PHP's strtoupper [[+headline:ucase]]
ucwords Transforms the first letter of a word to uppercase. Similar to PHP's ucwords [[+title:ucwords]]
ucfirst Transforms the first letter of the string to uppercase.Similar to PHP's ucfirst [[+name:ucfirst]]
htmlent, htmlentities Similar to PHP's htmlentities. Uses the current value the system setting "modx_charset" with flag ENT_QUOTES
[[+email:htmlent]]
esc,escape Safely escapes character values using regex and str_replace. Also escapes [, ] and ` [[+email:escape]]
strip Replaces all linebreaks, tabs and multiple spaces with just one space [[+textdocument:strip]]
stripString Strips string of specified value [[+name:stripString=`Mr.`]]
replace Replaces one value with another [[+pagetitle:replace=`Mr.==Mrs.`]]
striptags, stripTags,notags,strip_tags Accepts a value to indicate which tags to allow. Similar to PHP's strip_tags [[+code:strip_tags=`<p>`]]
len,length, strlen
Counts the length of the passed string. Similar to PHP's strlen [[+longstring:strlen]]
reverse, strrev Similar to PHP's strrev [[+mirrortext:reverse]]
wordwrap Similar to PHP's wordwrap. Takes optional value to set wordwrap position. [[+bodytext:wordwrap=`80`]]
wordwrapcut Similar to PHP's wordwrap, with word cutting enabled. Takes optional value to set wordwrap position. [[+bodytext:wordwrapcut=`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`]]
tag Displays the raw element without the :tag. Useful for documentation. [[+showThis:tag]]
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,empty, isempty Returns the input value if empty [[+name:default=`anonymous`]]
notempty, !empty, ifnotempty, isnotempty Returns the input value if not empty [[+name:notempty=`Hello [[+name]]!`]]
nl2br Similar to PHP's nl2br [[+textfile:nl2br]]
date Similar to PHP's strftime. Value is format. See Date Formats. [[+birthyear:date=`%Y`]]
strtotime Similar to PHP's strtotime. Takes in a date. See Date Formats. [[+thetime:strtotime]]
fuzzydate Returns a pretty date format with yesterday and today being filtered. Takes in a date. [[+createdon:fuzzydate]]
ago Returns a pretty date format in seconds, minutes, weeks or months ago. Takes in a date. [[+createdon:ago]]
md5 Similar to PHP's md5. [[+password:md5]]
cdata Wraps the text with CDATA tags [[+content:cdata]]
userinfo Returns the requested user data. The element must be a modUser ID. The value field is the column to grab. [[+modx.user.id:userinfo=`username`]]
isloggedin Returns true if user is authenticated in this context. [[+modx.user.id:isloggedin]]
isnotloggedin Returns true if user is not authenticated in this context. [[+modx.user.id:isnotloggedin]]
urlencode Similar to PHP's urlencode [[+mystring:urlencode]]
urldecode Similar to PHP's urldecode [[+myparam:urldecode]]

Caching

In general, any content in a placeholder that you think might change dynamically should be uncached. For example:

[[+placeholder:default=`A default value!`]]

This means that this could sometimes be empty, and sometimes not. Why would you ever want that cached? That would eliminate the point of the output modifier.

Sometimes, output modifiers can be used on a cached placeholder - but only if you're calling the Snippet that sets them cached as well. Otherwise, you're performing an illogical maneuver - trying to cache statically something that was never meant to be static.

In general, the rule is: If you set a placeholder in an uncached Snippet, the placeholder needs to be uncached as well if you expect the content of the placeholder to differ.

Using an Output Modifier with Tag Properties

If you have properties on the tag, you'll want to specify those after the modifier:

[[!getResources:default=`Sorry - nothing matched your search.`?
   &tplFirst=`blogTpl`
   &parents=`2,3,4,8`
   &tvFilters=`blog_tags==%[[!tag:htmlent]]%`
   &includeTVs=`1`]]

Creating a Custom Output Modifier

Also, Snippets can be used as custom modifiers. 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. If the snippet returns an empty string, the output will not be modified at all.

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 output modifiers instead of a Snippet can be accomplished simply by utilizing the userinfo modifier. Select the appropriate column from the table and specify it as the property of the output modifier, like so:

User Internal Key: [[!+modx.user.id:userinfo=`internalKey`]]<br />
User name: [[!+modx.user.id:userinfo=`username`]]<br />
Full Name: [[!+modx.user.id:userinfo=`fullname`]]<br />
Role:  [[!+modx.user.id:userinfo=`role`]]<br />
E-mail: [[!+modx.user.id:userinfo=`email`]]<br />
Phone: [[!+modx.user.id:userinfo=`phone`]]<br />
Mobile Phone: [[!+modx.user.id:userinfo=`mobilephone`]]<br />
Fax: [[!+modx.user.id:userinfo=`fax`]]<br />
Date of birth: [[!+modx.user.id:userinfo=`dob`:date=`%Y-%m-%d`]]<br />
Gender: [[!+modx.user.id:userinfo=`gender`]]<br />
Country: [[+modx.user.id:userinfo=`country`]]<br />
State: [[+modx.user.id:userinfo=`state`]]<br />
Zip Code: [[+modx.user.id:userinfo=`zip`]]<br />
Photo: [[+modx.user.id:userinfo=`photo`]]<br />
Comment: [[+modx.user.id:userinfo=`comment`]]<br />
Password: [[+modx.user.id:userinfo=`password`]]<br />
Cache Password: [[+modx.user.id:userinfo=`cachepwd`]]<br />
Last Login: [[+modx.user.id:userinfo=`lastlogin`:date=`%Y-%m-%d`]]<br />
The Login:[[+modx.user.id:userinfo=`thislogin`:date=`%Y-%m-%d`]]<br />
Number of Logins: [[+modx.user.id:userinfo=`logincount`]]

[[!+modx.user.id]] defaults to the currently logged in user ID. You can of course replace that with [[*createdby]] or other resource field or placeholders that return a numeric ID representing a user.

Note that the user ID and username is already available by default in MODx, so you dont need to use the "userinfo" modifier:
[[!+modx.user.id]] - Prints the ID
[[!+modx.user.username]] - Prints the username

You will most likely want to call these uncached (see note about caching above) to prevent unexpected results.

See Also

Labels

filters filters Delete
input input Delete
filter filter Delete
output output Delete
modifers modifers Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.