Modifying placeholder output with PHx
PHx ("placeholders extended") is a MODx plugin which can manipulate the output of placeholders (including document fields, template variable output and site settings) in documents and chunks. Ditto includes its own copy of PHx functions, so they are available without installing the plugin. The "internal" PHx functions are enabled by default; you can disable them using the parameter &phx=`0`.
Typical uses of PHx with Ditto:
- To output alternative tags (or no tags) for an empty field
- To format a date when the [+date+] placeholder has already been assigned, or as an alternative to the &dateSource/&dateFormat/[+date+] routine
- To transform case of the output
- To carry out complex conditional or arithmetic processing of placeholder output
Important note concerning pagination: If you install the PHx plugin (to use it in non-Ditto documents), you must make the Ditto call uncached, and make the page containing it non-cacheable in the Page Settings tab for &paginate (also &debug and &randomize) to work.
When the PHx plugin is not installed (or is disabled) you have to call Ditto uncached when using pagination. Reminder: [[snippet]] = cached, [!snippet!] = uncached.
The basic use of PHx with placeholders is well documented in the MODx Wiki. If the built-in modifiers do not suit, have a look at the list of custom modifiers. It is quite easy to create your own custom modifier if you need special processing, or if all those colons in PHx conditionals give you headaches.
Some examples in the context of Ditto template chunks:
No tags for an empty introtext field
Item 1: Has an introtext
Item 2: has no introtext
Alternative dates and date formats
[+pkDate:date=`%d %B %Y`+], [+createdon:date=`%Y-%m-%d %H:%M`+] (View template)
Cras velit. ITEM 467 Integer luctus. In nec
In eu ITEM 466 purus eu mi sollicitudin
Manipulate page string
[+pagetitle:ucase:reverse:limit=`12`:reverse+] (View template)