MODX Output modifiers bring near limitless possibilities to your code by allowing you to execute PHP code on a value. Here are some of my favourite one-liners and useful tips on using output modifiers.
HTML
<!-- Output the current year by setting the placeholder year to a value of now: [[!+year:default=`now`:strtotime:date=`%Y`]] -->
[[!+year:default=`now`:strtotime:date=`%Y`:tag]]
<!-- Outputs the current MODX users full name -->
[[!+modx.user.id:userinfo=`fullname`:tag]]
<!-- Simple if else statement -->
[[*pagetitle:eq=`Home`:then=`You are on the Home page`:else=`You are not on the Home page`:tag]]
<!-- Generate a thumbnail using PHPThumb -->
[[*image:tag:phpthumbof=`w=120&h=120`]]
How to create an Output Modifier for Modx?
MODX output modifiers are basically snippets that take the value of the placeholder and perform operations on it. To make your own, create a new snippet and grab the value of the placeholder using $input.
Below we'll create an output modifier that takes a comma-separated list of numbers and returns them in descending order, the snippet is called orderdesc and you can use the modifier like so: [[*numbers:orderdesc:tag]]
If we have a TV called numbers with a value of 5, 8, 2, 9, 1, 7, 3, it will return 9, 8, 7, 5, 3, 2, 1
PHP
<?php
// Explode , in string to array
$arr = explode(',', $input);
// Sort array from High to low
arsort($arr);
// turn back into a string
return implode(', ', $arr);