Smarty plugins
This article presumes that you understand how Saurus CMS Extensions work.
Smarty plugins are PHP functions that are included only when they are called from templates.
Plugin files must be named as follows:
type.name.php
Where type is one of these plugin types:
- function
- modifier
- block
- compiler
- prefilter
- postfilter
- outputfilter
- resource
- insert
And name should be a valid identifier; letters, numbers, and underscores only, see php variables.
Some examples: function.html_select_date.php, resource.db.php, modifier.spacify.php.
plugin functions inside the PHP files must be named as follows:
smarty_type_name()
The meanings of type and name are the same as above.
An example modifier name foo would be function smarty_modifier_foo().
For a more detailed information about Smarty plugins go to http://www.smarty.net/manual/en/plugins.php.
When adding your own custom made plugins to Saurus CMS we strongly suggest you use CMS's Extensions, but you can also put the plugin file into "classes/smarty/lib/plugins/" folder.
With an extension you must specify the folder where the plugins are in extension.config.php file in your extension's folder with the following syntax:
$EXTENSION['smarty_plugins'] = '/path/to/your/plugins/folder';
An example would be:
$EXTENSION['smarty_plugins'] = '../../../extensions/'.$EXTENSION['name'].'/smarty_plugins';
When using the relative path like in the above example keep in mind that for Smarty the path starts inside the folder "/classes/smarty/" not in the website root folder.
Now add the plugin files to the folder and use them in your templates.
Simple modifier example, file name: modifier.capitalize.php
<?php
function smarty_modifier_capitalize($string)
{
return ucwords($string);
}
?>
