Concatenate a variable and a string in Smarty in order to include a file

Viewed 6552

In a tpl file, i need to include a file dynamically, with a concatenation of a string and a variable.

This work (no concatenation) :

{include file="catalog/_partials/faq-86.tpl"}

Then, i would like to replace "86" by a variable (the product id).

Here is what i’ve tried (based on other answers on stackoverflow , on smarty forum or smarty documentation):

1)

{include file="catalog/_partials/{$product.name}.tpl"}

2)

{assign var="id_pr" value="85"}
{include file="catalog/_partials/.$id_pr.tpl"}

3)

{assign var="id_pr" value="85"}
{include file="catalog/_partials/$id_pr.tpl"}

4)

{include file="{'catalog/_partials/'}{$product.name}{'.tpl'}"}

5)

{assign var='url' value="{'catalog/_partials/'}{$product.name}{'.tpl'}"} 
{include file=$url}

Here is the smarty error :

Syntax error in template "templates/catalog/product.tpl" on line 273 "{include file="catalog/_partials/{$product.name}.tpl"}" variable template file names not allow within {block} tags

So my, question, is it possible to concatenate a variable and a string in order to include a file ?

I know it is not the best approach but for templating purpose, I need to quickly load different tpl files on different product page.

I think it is possible since this condition is working (no concatenation but the file is included dynamically) :

{if $product.id === 85}

    {include file="catalog/_partials/faq-85.tpl"}

{elseif $product.id === 86}

    {include file="catalog/_partials/faq-86.tpl"}

{/if}
1 Answers
Related