使用$smarty->fetch('mytemplate.tpl')
方法时如何从模板中卸载或禁用smarty core插件
例如模板mytemplate.tpl
包含{html_options}和{html_table}
当使用$smarty->fetch('mytemplate.tpl')
时,smarty只解析{html_options},而不解析{html_table}
从插件文件夹中删除function.html_table.php
不是一个选项,因为它仍然在使用另一个$smarty->fetch()
调用
一种可能的解决方案是从Smarty_Security
类扩展,并通过使用
$smarty->enableSecurity($instanceOfClass)
一旦fetch方法被调用,disableSecurity
方法就会重新启用所有的plugins/tags/modifiers
。
不幸的是,当使用enableSecurity和禁用函数时,会抛出异常
另一种方法是替换所有的标签/变量/…您希望在调用 $smarty->fetch([...])
preg_replace
来禁用{literal}{forbiddenTags}{/literal}例子# negate regular expression pattern to allow only the below tags
$pattern = "/'{(?!allowedTag1|allowedTag2).*?'}/";
$replacement = '{literal}$0{/literal}';
$content = preg_replace($pattern, $replacement, $content);
$smarty->fetch("string:" . $content);
关于Security类的更多详细信息请参见:http://www.smarty.net/docs/en/advanced.features.tpl