在一个tpl文件中,我需要动态地包含一个文件,包含一个字符串和一个变量的串联。在Smarty中连接一个变量和一个字符串以包含一个文件
该作品(无连接):
{include file="catalog/_partials/faq-86.tpl"}
的话,我想通过一个变量(产品ID)来取代 “86”。
这里是我已经试过(基于计算器其他答案,对智者论坛或智者文档):
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}
这里是smarty的错误:
语法错误在模板上线273 “模板/目录/ product.tpl”“{包含file =“目录/ _partials/{$ product.name} .tpl”}“变量 模板文件名不允许在{block}标记内
所以我的问题是,是否可以连接变量和字符串以包含文件?
我知道这不是最好的方法,但为了模板的目的,我需要在不同的产品页面上快速加载不同的tpl文件。
我认为这是可能的,因为这种情况是工作(没有串联,但该文件是动态包含):
{if $product.id === 85}
{include file="catalog/_partials/faq-85.tpl"}
{elseif $product.id === 86}
{include file="catalog/_partials/faq-86.tpl"}
{/if}
您正在使用哪个版本的smarty?我在某个项目中使用smarty3,第一种风格对我来说正常工作,所以你{block}标记? – hassan
我不知道,我使用Prestashop 1.7(最新版本),所以我想这是最新的smarty版本,但我需要检查这一点。 –
看起来像prestashop使用smarty分叉版本,https://github.com/PrestaShop/smarty – hassan