如何自动加载smarty插件

问题描述 投票:19回答:1

我们有一个带有Smarty模板引擎的PHP脚本插件,

它可以在{plugin_name}的模板文件中使用,但需要确保它在每个模板文件上,问题是:

有没有办法在脚本加载时自动加载此插件?

脚本不是开源的,但Smarty及其文件(如Smarty.class.php等)未加密。

编辑

我需要做的就是在模板文件加载之前自动加载Smarty插件(与数据库的交互很少),这是否可以/只用Smarty文件实现? (脚本本身是加密的,但Smarty_Compiler.class.php,Smarty.class.php,Config_File.class.php和其他聪明的核心功能都是开源的)

php smarty
1个回答
1
投票

这取决于您使用的Smarty版本。

使用Smarty 3,您可以:

$smarty = new Smarty();
$smarty->setTemplatesDir(....);
$smarty->addPluginsDir('/path/to/your/plugins');
... stuff.
$smarty->display('template.tpl');

另见:https://www.smarty.net/docs/en/api.add.plugins.dir.tpl

有了Smarty2,我想你需要做更像这样的事情 -

https://www.smarty.net/docsv2/en/api.register.function.tpl

或者,使用正确的文件名和函数名将函数放入libs / plugins目录中......

© www.soinside.com 2019 - 2024. All rights reserved.