How to add my new plugin to smarty?
I want to add a SmartyFilter
class to smart开发者_开发问答y, but where to put the file so smarty can find it automatically?
Smarty comes with a plugins
subdirectory. Throw your script in there and smarty will find your plugin in there.
You can extend that path by adding other directories to $smarty->plugins_dir[]
$smarty->plugins_dir[] = 'includes/my_smarty_plugins';
If your plugins are dependant on each other you may want to require a plugin yourself by doing:
require_once $smarty->_get_plugin_filepath('function', 'html_options');
This would load a plugin in plugin_dir
with the name function.html_options.php
.
copy and paste theme into "plugins" sub directory in main smarty folder, the file name must be leading with function.filename.php
In recent versions of Smarty, you have a method to add a plugin folder:
// Add a folder of plugins
$smarty->addPluginsDir('./plugins_1/');
// Check what plugins folders are registered
var_dump($smarty->getPluginsDir());
/* DUMP:
array(2) {
[0]=>string() "./plugins/"
[1]=> string() "./plugins_1/"
}
*/
For more information, you can read the addPluginsDir() documentation.
精彩评论