php - 如何自动加载 smarty 插件

标签 php smarty

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

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

is there a way to auto-load this plugin whenever the scripts loads?

脚本不是开源的,但是Smarty和它的文件(比如Smarty.class.php等)没有加密。

编辑

我需要做的就是在加载模板文件之前自动加载一个 Smarty 插件(它与数据库的交互很少),这是否可能/只能通过 Smarty 文件实现? (脚本本身是加密的,但Smarty_Compiler.class.php、Smarty.class.php、Config_File.class.php等smarty核心函数是开源的)

最佳答案

这取决于您使用的 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 目录中,并使用正确的文件名和函数名...

关于php - 如何自动加载 smarty 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39137267/

相关文章:

php - Windows上的信号处理

php - Telegram Bot sendDocument(托管服务器上的 php)

Mysql 在 2 个主键上插入新行

php - 调用非对象的成员函数

php - 聪明的连接

php - PHP 中没有 glob 函数

php - Google Analytics 获得相同的域推荐计数

PHP:使用 anchor 标记提交表单数据

javascript - 点击事件时从数据库获取价格

templates - 创建可通过 PrestaShop 中的所有模板访问的变量