简体   繁体   English

Smarty在var中包含传递数组

[英]Smarty include passing array in var

I try to pass an array element in include's var. 我尝试在include的var中传递一个数组元素。

But I still have this error : 但是我仍然有这个错误:

Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "file:/home/technique/www/site/tpl/home.html" on line 6 "{include file='include/article-latest.html' class='col-50' title=$article.TITLE tag=ARTICLE_CATEGORY.$article.CATEGORY img=$article.THUMBNAIL view='3526' share='564'}" - Unexpected ".", expected one of: "}" <-- thrown in /home/technique/www/common/lib/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 6 致命错误:未捕获-> Smarty编译器:第6行“ {include file ='include / article-latest.html'类”中的模板“ file:/home/technique/www/site/tpl/home.html”中的语法错误='col-50'title = $ article.TITLE标签= ARTICLE_CATEGORY。$ article.CATEGORY img = $ article.THUMBNAIL view ='3526'share ='564'}“-意外的”。“,预期其中之一:”} “ <-在第6行的/home/technique/www/common/lib/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php中抛出

My code : 我的代码:

{foreach $latest_article.0 as $article}
    {include file='include/article-latest.html' class='col-50' title=$article.TITLE tag=ARTICLE_CATEGORY.$article.CATEGORY img=$article.THUMBNAIL view='3526' share='564'}
{/foreach}

Apparently, the problem is using the constant ARTICLE_CATEGORY. 显然,问题出在使用常量ARTICLE_CATEGORY。 It seem like the php constant isn't interpreted by smarty... 似乎php常量没有被smarty解释...

PHP constants in Smarty can be called by $smarty.const.CONSTANT_NAME Reference is here - https://www.smarty.net/forums/viewtopic.php?p=25903&sid=92c2eb2c177f8f82ae084361ee6c4400 可以通过$ smarty.const.CONSTANT_NAME调用Smarty中的PHP常量。https: //www.smarty.net/forums/viewtopic.php?p = 25903&sid = 92c2eb2c177f8f82ae084361ee6c4400

{foreach $latest_article.0 as $article}
    {include file='include/article-latest.html' class='col-50' title=$article.TITLE tag=$smarty.const.ARTICLE_CATEGORY.$article.CATEGORY img=$article.THUMBNAIL view='3526' share='564'}
{/foreach}

besides take into account the following: - TITLE and CATEGORY might be constants in the code too therefore must be called via $smarty.const.TITLE and $smarty.const.CATEGORY appropriately; 除了考虑以下因素:-TITLE和CATEGORY在代码中也可能是常量,因此必须通过$ smarty.const.TITLE和$ smarty.const.CATEGORY进行适当的调用; - ARTICLE_CATEGORY is constant so it is strange that it is used as array; -ARTICLE_CATEGORY是常量,因此用作数组很奇怪; - ARTICLE.$article.CATEGORY might be too deep-level array and might be processed by Smarty incorrectly (because of too many dots). -ARTICLE。$ article.CATEGORY可能是太深的数组,并且可能被Smarty错误地处理(由于点太多)。 To fix it, you might need to assign variables, for example: 要修复它,您可能需要分配变量,例如:

{assign var="article_category" value=$smarty.const.ARTICLE_CATEGORY}
{foreach $latest_article.0 as $article}
    {include file='include/article-latest.html' class='col-50' title=$article.TITLE tag=$article_category.$article.CATEGORY img=$article.THUMBNAIL view='3526' share='564'}
{/foreach}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM