2014-02-10 29 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}