php - Smarty include passing array in var -
i try pass array element in include's var.
but still have 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 1 of: "}" <-- thrown in /home/technique/www/common/lib/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 6
my code :
{foreach $latest_article.0 $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, problem using constant article_category. seem php constant isn't interpreted smarty...
php constants in smarty can called $smarty.const.constant_name reference here - https://www.smarty.net/forums/viewtopic.php?p=25903&sid=92c2eb2c177f8f82ae084361ee6c4400
{foreach $latest_article.0 $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 account following: - title , category might constants in code therefore must called via $smarty.const.title , $smarty.const.category appropriately; - article_category constant strange used array; - article.$article.category might deep-level array , might processed smarty incorrectly (because of many dots). fix it, might need assign variables, example:
{assign var="article_category" value=$smarty.const.article_category} {foreach $latest_article.0 $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}
Comments
Post a Comment