Jump to main content Jump to doc navigation

modX::setPlaceholders

Sets a collection of placeholders stored in an array or as object vars. An optional namespace parameter can be prepended to each placeholder key in the collection, to isolate the collection of placeholders.

Note that unlike modX.toPlaceholders and modX.getChunk, this function does not add separators between the namespace and the placeholder key. Use toPlaceholders() when working with multi-dimensional arrays or objects with variables other than scalars so each level gets delimited by a separator.

Syntax

API Doc: modX::setPlaceholders()

void setPlaceholders (array|object  $placeholders, [string $namespace = ''])

Unlike getChunk, the $placeholders array can not be deeply nested. It must be a simple associative array.

Example

Add an array of placeholders, and prefix 'my.' to their key.

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

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
  • Lefthandmedia
  • Murray Wood
  • eydolan
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

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

Learn more