How To ...

Create a Snippet

Snippets are created via the Elements option in the manager interface by going to Elements then clicking New Snippet (the second icon from the left).

New Snippet Icon

To create an example snippet, after clicking new Snippet, set the Snippet Name to ‘example’ and in the Snippet (PHP) field put:

$value1 = isset($value1) ? $value1 : 'Value 1 not give';
$value2 = isset($value2) ? $value2 : 'Value 2 not give';

echo "Value 1 = $value1<br />\n";
echo "Value 2 = $value2<br />\n";

echo time();

Save the snippet and return to the dashboard then select Documents, choose one of the documents to add the snippet to, if you followed the Getting Started Guide then you should have a My Home Page document. Add the snippet to the content with:

[[example &value1=`1234`]]

Now when you access the document through the front end the snippet will run. The snippet outputs the values of value1 and value2 if given followed by the current timestamp. The timestamp will not be updated on page refreshes as it is cached, if the snippet had been called as [[!example &value1=`1234`]] then the snippet would not be cached and the time will update on each page load.

Overriding Existing Snippets

If you need to change the behavior of a built in snippet then you can simply create a new snippet with the same name as the one you want to replace. clearFusionCMS will use the snippets created under Elements before it uses the ones supplied within the core system or modules.

 

View Core Snippets


 

How to use your ...


How To ...