Smarty + Prestashop:如果存在则包含模板

时间:2014-02-10 11:40:34

标签: syntax smarty prestashop

我有以下代码,如果它存在,我想包含一个模板,否则回退到明确输出内容。

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

据我所知,我的语法是正确的,但我可能是错的,因为我是新手。知道我做错了什么(我想也许是串联)?

2 个答案:

答案 0 :(得分:0)

它看起来像连接问题。使用"反叛"评估Smarty变量:

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

有关详细信息,请参阅Embedding Vars in Double Quotes

答案 1 :(得分:0)

如果您的文件位于同一文件夹中,请尝试此操作:

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