The anatomy of a snippet call
Recently I came across to a nice wiki article "Snippet call anatomy" written by our Testing Team member, dev_cw. Be sure to check it out, especially the new users.
This one will also be helpful, Common snippet error messages and their meaning.
Comments:
2
by dev_cw 09-May-08 06:49 PM
There is a wiki article <a href"http://wiki.modxcms.com/index.php/Creating_Snippets">"Creating Snippets"</a> that has some good information for creating snippets.
To answer your questions: The snippet parameters ¶m=`value` are reflected as variables to be used within the snippet. So if you have a parameter named &data this is available as a variable in your snippet as $data and can then be used by the snippet code.
The output can be generated basically the same way as with any php function. I use the return command, but others use echo.
Here is a basic example putting the two concepts together. Take this snippet call for example:
[ [mySnippet? &width=`100` &height=`300` ] ]
And here is the snippet:
<?php
$output = "The width is ".$width.", and the height is ".$height.".";
return $output;
?>
This will output: "The width is 100, and the height is 300."
To answer your questions: The snippet parameters ¶m=`value` are reflected as variables to be used within the snippet. So if you have a parameter named &data this is available as a variable in your snippet as $data and can then be used by the snippet code.
The output can be generated basically the same way as with any php function. I use the return command, but others use echo.
Here is a basic example putting the two concepts together. Take this snippet call for example:
[ [mySnippet? &width=`100` &height=`300` ] ]
And here is the snippet:
<?php
$output = "The width is ".$width.", and the height is ".$height.".";
return $output;
?>
This will output: "The width is 100, and the height is 300."
3
Placeholders by Aikdo 10-Jun-08 02:30 PM
Though it is nicer for the future if even with a small script like this you use placeholders.
4
Placeholders by Aikdo 10-Jun-08 03:02 PM
Though it is nicer for the future if even with a small script like this you use placeholders.
You must be logged into the forums to comment. Please login

How do I set up a snippet parameter for a snippet call?
How do I get the output to return?