MODX Cloud

The Most Productive MODX Learning Playground Ever

Claim Free Lab Account

Snippets

Skip to end of metadata
Go to start of metadata

Snippets are useful for adding logic to websites. They can be used to create menus, determine who is logged in, or any other thing possible with the API.

Usage

Cached:

[[snippetName]]

Uncached

[!snippetName!]

Accessing Snippets via the MODx API 

Snippets can also be run inside of other snippets by using the MODx API:

Usage

$modx->runSnippet('snippetName' [, $params]);

You can optionally pass parameters to your snippet

$params => array('dog' => 'Max');
$modx->runSnippet('mySnippet', $params);

Then inside your Snippet ("mySnippet"), you will have access to the corresponding variables via PHP's extract function, or you can access all parameters inside of the $modx object:

// inside "mySnippet"
print $dog; // prints 'Max'
print_r( $modx->event->params ); // prints array('dog' => 'Max');

See also

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.