Stefan Dunn
Stefan Dunn

Reputation: 5513

Smarty + Prestashop: Include template if exists

I've got the following code, which I would like to include a template if it exists otherwise fallback to outputting the content plainly.

{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'm thinking maybe concatenation)?

Upvotes: 4

Views: 996

Answers (2)

totemax
totemax

Reputation: 46

Try this 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}

Upvotes: 1

klimpond
klimpond

Reputation: 766

It looks like concatenation problem. Use "backticks" to evaluate a Smarty variable:

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

For more information see Embedding Vars in Double Quotes

Upvotes: 0

Related Questions