Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Syntax Smarty+;Prestashop:包含模板(如果存在)_Syntax_Smarty_Prestashop - Fatal编程技术网

Syntax Smarty+;Prestashop:包含模板(如果存在)

Syntax Smarty+;Prestashop:包含模板(如果存在),syntax,smarty,prestashop,Syntax,Smarty,Prestashop,我有以下代码,如果模板存在,我希望包含一个模板,否则会退回到直接输出内容 {if $smarty->template_exists("$tpl_dir./cms.tpl")} {include file="$tpl_dir/$cms->link_rewrite.tpl"} { else } {$cms->content} { /if } 据我所知,我的语法是正确的,但我可能是错误的,因为我是新手。知道我做错了什么吗(我想可能是连接)?看起来像是连接问题。使用“反勾

我有以下代码,如果模板存在,我希望包含一个模板,否则会退回到直接输出内容

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

据我所知,我的语法是正确的,但我可能是错误的,因为我是新手。知道我做错了什么吗(我想可能是连接)?

看起来像是连接问题。使用“反勾号”评估Smarty变量:

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

有关详细信息,请参见

如果文件位于同一文件夹中,请尝试以下操作:

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