2014-02-10 98 views
3

我有下面的代码,如果它存在,我想包括一个模板,否则回退到输出内容。Smarty + Prestashop:包含模板(如果存在的话)

{if $smarty->template_exists("$tpl_dir./cms.tpl")} 
    {include file="$tpl_dir/$cms->link_rewrite.tpl"} 
{ else } 
    {$cms->content} 
{ /if } 

据我了解,我的语法是正确的,但我可能是错的,因为我是新手。任何想法我做错了(我想也许连接)?

回答

0

看起来像串接问题。使用“反引号”来评价一个Smarty的变量:

$smarty->template_exists("`$tpl_dir`/cms.tpl") 

欲了解更多信息,请参阅Embedding Vars in Double Quotes

+0

使用同样的方法在'{包括文件= ....}' – klimpond

0

试试这个,如果你的文件是在同一文件夹:

{assign var="file" value="`$smarty.current_dir`/file_name.tpl"} 
{if $file|file_exists} 
{include file=$file} 
{/if}