开发者

How to add my new plugin to smarty?

开发者 https://www.devze.com 2023-02-23 00:00 出处:网络
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 smar

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号