Php Smarty{include}文件+;标记(如果存在),否则回退到文件
我正在开发一款白标签产品,希望能够快速覆盖一些模板,但不是全部模板 我的想法是要有这样的东西,比如说Php Smarty{include}文件+;标记(如果存在),否则回退到文件,php,smarty,smarty3,Php,Smarty,Smarty3,我正在开发一款白标签产品,希望能够快速覆盖一些模板,但不是全部模板 我的想法是要有这样的东西,比如说index.tpl {include file="header.tpl" tag=$whitelabelname} {include file="body.tpl" tag=$whitelabelname} {include file="footer.tpl" tag=$whitelabelname} 如果有任何方法,我希望能够自动包含文件header-whitelabelname.tpl(
index.tpl
{include file="header.tpl" tag=$whitelabelname}
{include file="body.tpl" tag=$whitelabelname}
{include file="footer.tpl" tag=$whitelabelname}
如果有任何方法,我希望能够自动包含文件header-whitelabelname.tpl(如果存在),或者header.tpl(如果不存在)
$tagTemplate = substr($template, 0, -4) . "-" . $tag . ".tpl";
if ( file_exists($tagTemplate) ) $template = $tagTemplate;
这样做的原因是,替代方案需要将所有模板文件更改为每个include上的一个大switch语句,这将导致非常大和复杂的模板
是否可以以某种方式扩展{include}
指令以包含我的逻辑,而不是自己手动更改smarty_internal_compile_include.php
谢谢您可以通过实现。检查文档页面上的示例。您必须在第一个函数中实现
文件\u exists()
逻辑。另外,请检查有关如何使用插件的方法。您无需更改Smarty编译器,Smarty可以通过实现插件以多种方式进行扩展。