Jump to main content Jump to doc navigation

modX::setPlaceholders

Sets a collection of placeholders from an array or object. An optional $namespace is prepended to each key in the collection to keep it apart from other placeholders.

Syntax

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

No separator is inserted — neither between the namespace and the key nor between the levels of a nested array. setPlaceholders(['a' => ['b' => 1]]) with an empty namespace therefore sets a single placeholder called ab.

Nested arrays are concatenated the same way: getChunk and toPlaceholders insert a dot between levels, setPlaceholders does not. For multi-dimensional arrays and objects with non-scalar values, use modX.toPlaceholders, which delimits each level with a separator (a dot by default).

Example

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

$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
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • JT Skaggs
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

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

Learn more