|
|
Written by Marion Consulting
|
|
Plugins are a nice way to extend the functionality of Smarty. You can create plugins for (functions, modifiers, prefilters, postfilters, and output filters). This tutorial will cover the creation of a very simple plugin. Smarty has excellent documentation and already a wealth of plugins available at http://smarty.php.net/contribs/plugins/ This plugin can be used on a live site, but it isn't very useful. It is only to demonstrate how to create plugins. Our plugin will take a name and return a message to the user. 1.) Name your file function.function_name.php and place it in your plugins directory - Ours will be named function.welcome_message.php 2.) Inside the code you should have a function named the same as your php file - function smarty_function_welcome_message($params, &$smarty){ 3.) The body of the function will perform some activity with the parameter (name) that was passed in. In this case output a mesage - return 'Hello ' . $params['name'] . ' we are happy that you are visiting our website';} 4.) Now you need to invoke the plugin from your tpl file - {welcome_message name='Marion Consulting'} 5.) You should receive the following output - Hello Marion Consulting we are happy that you are visiting our website Good luck!
|
|
|