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? &modId=`6` &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? &modId=`6` &parents=`455` &tpl=`ditto.phx.dates` &dateSource=`pkDate` &dateFormat=`%d/%m/%y` &randomize=`1` &display=`2` !]

Praesent ac ITEM 468 ligula. Nam risus tortor,

Custom publication date: 26/10/07
Alternative date format: 26 October 2007
Document created: 2003-12-13 12:30

Duis tristique ITEM 463 urna id metus. Maecenas

Custom publication date: 15/02/06
Alternative date format: 15 February 2006
Document created: 2003-03-28 14:02

Manipulate page string

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

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

Nunc ut ITEM 204 metus ac elit aliquam

This title ends: ELIT ALIQUAM

Suspendisse potenti. ITEM 207 Sed fringilla. Sed ut

This title ends: ILLA. SED UT