Jump to main content Jump to doc navigation

modX::runSnippet

Process and return the output from a PHP snippet by name.

Syntax

API Doc: modX::runSnippet()

string runSnippet (string $snippetName, [array $params = array ()])
  • $snippetName (string) The name of the Snippet you wish to call. required
  • $params (array) An associative array of properties to pass to the snippet

Example

Run the 'Welcome' snippet with some custom parameters:

Examples

$output = $modx->runSnippet('Welcome',array(
   'name' => 'John'
));
echo $output; // prints 'Welcome John!'

Handy Hint

When you call a Snippet using runSnippet, the Snippet code is always executed: the results are never returned from cache. It's equivalent to running the Snippet using the [[!uncached]] syntax.

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