[英]smarty3 detection if template was included by {include}
In smarty3, is there a way to find out if a smarty template was included my the {include} tag? 在smarty3中,是否有办法找出{include}标签中是否包含smarty模板? I know i just could do it that way for example: 我知道我可以这样做,例如:
{include file="blahblah.tpl" included=1}
And inside blahblah.tpl 在blahblah.tpl里面
{if $included==1}
yadda yadda yadda
{/if}
I just want to know if there's a simpler way. 我只想知道是否有更简单的方法。
Before including your template file , you can check with template_exists() , to see if template exists 在包含模板文件之前,可以使用template_exists()检查模板是否存在
if( !$smarty->template_exists($mid_template) ){
$mid_template = 'page_not_found.tpl';
} else {
$mid_template = 'blahblah.tpl';
}
$smarty->assign('content_template', $mid_template);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.