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` !]

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

Vestibulum ante ITEM 461 ipsum primis in faucibus

Custom publication date: 12/06/05
Alternative date format: 12 June 2005
Document created: 2002-06-28 21:19

Manipulate page string

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

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

Praesent ac ITEM 229 ligula. Nam risus tortor,

This title ends: ISUS TORTOR,

Praesent ac ITEM 146 ligula. Nam risus tortor,

This title ends: ISUS TORTOR,