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.
$388 per month—let's make that $500!Learn more
Snippets are MODX's answer to inline PHP code. They provide customizable dynamic content, such as menus, blog or news listings, search and other form-based functionality and anything else that your site needs to generate on-demand.
Using a Snippet¶
Once you have a Snippet installed, you can use it simply by putting its tags in your template, a chunk or TV, or a document's content wherever you want the Snippet's output to be displayed.
If you expect the snippet code to be dynamic for different users, you can also call a snippet uncached:
Snippets can have Properties, which can be passed in the Snippet call, like so:
[[!Wayfinder? &startId=`0` &level=`1`]]
You can also aggregate these Properties into a Property Set, which is a dynamic collection of properties that can be attached to any Snippet (or Element for that matter). This allows you to share common property configs in a snippet call in one place.
Say you had a Property Set called 'Menu' with
startId set to 0 and
level set to 1:
would then load those properties automatically into the Snippet. And even those properties can be overridden:
which would override the set's value on
level of 1, setting it instead to 2.