Jump to main content Jump to doc navigation

modX::toPlaceholders

Sets placeholders from values stored in arrays and objects.

Each recursive level in the $placeholders array adds to the prefix, building an access path using an optional separator.

Syntax

API Doc: modX::toPlaceholders()

array toPlaceholders (array|object  $subject, [string $prefix = ''], [string $separator = '.'], [boolean $restore = false])

Example

Set an array of placeholders and prefix with 'my.' Returns a multi-dimensional array containing up to two elements: 'keys' which always contains an array of placeholder keys that were set, and optionally, if the restore parameter is true, 'restore' containing an array of placeholder values that were overwritten by the method.

$modx->toPlaceholders(array(
  'name' => 'John',
  'email' => '[email protected]',
),'my');

Example with Nested Placeholders

Using nested data as the $placeholders:

$modx->toPlaceholders(array(
  'document' => array('pagetitle' => 'My Page')
));

Corresponds to placeholders such as [[+document.pagetitle]]

Note that using a $prefix on nested placeholders adds the $prefix to the front of each key. For example:

$modx->toPlaceholders(
  array(
    'test' => 'this',
    'document' => array('pagetitle' => 'My Page')
  ), 'tmp'
);

Would have placeholders such as [[+tmp.test]] and [[+tmp.document.pagetitle]]

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • eydolan
  • Lefthandmedia
  • Murray Wood
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$306 per month—let's make that $500!

Learn more