Smarty + Prestashop: enable the template, if it exists

I have the following code that I would like to include in the template, if it exists otherwise, to return the content directly.

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

As far as I understand, my syntax is correct, but I could be wrong, as I am new to this. Any idea what I am doing wrong (I think maybe concatenation)?

+3
source share
2 answers

Sounds like a concatenation problem. Use "backticks" to evaluate the Smarty variable:

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

See Inserting Vars in Double Quotes for more information.

0
source

Try if your file is in the same folder:

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

All Articles