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:

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

[+introtext:isnot=``:then=`<div class="ditto_summary"></div>`+]
(View template)

[[Ditto? &tpl=`ditto.phx` ]]

Item 1: Has an introtext

Introtext for item 1
Body of item 1

Item 2: has no introtext

Body of item 2

Alternative dates and date formats

[+pkDate:date=`%d %B %Y`+], [+createdon:date=`%Y-%m-%d %H:%M`+] (View template)

[!Ditto? &parents=`455` &tpl=`ditto.phx.dates` &dateSource=`pkDate` &dateFormat=`%d/%m/%y` &randomize=`1` &display=`2` !]

Cras velit. ITEM 467 Integer luctus. In nec

Custom publication date: 17/06/07
Alternative date format: 17 June 2007
Document created: 2003-12-06 06:03

In eu ITEM 466 purus eu mi sollicitudin

Custom publication date: 02/03/07
Alternative date format: 02 March 2007
Document created: 2003-09-06 20:22

Manipulate page string

[+pagetitle:ucase:reverse:limit=`12`:reverse+] (View template)

[!Ditto? &parents=`6` &tpl=`ditto.phx.transform` &display=`2` &randomize=`1` !]

Quisque varius ITEM 183 scelerisque dolor. Curabitur volutpat

This title ends: TUR VOLUTPAT

Nunc viverra, ITEM 122 dolor in rutrum vestibulum,

This title ends: VESTIBULUM,