0

I try to pass an array element in include's 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

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. It seem like the php constant isn't interpreted by smarty...

1
  • To access PHP constants in Smarty, you can use {$smarty.const.MY_CONSTANT} which is smarty.net/docs/en/… Commented Aug 20, 2017 at 16:38

1 Answer 1

1

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

{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; - ARTICLE_CATEGORY is constant so it is strange that it is used as array; - ARTICLE.$article.CATEGORY might be too deep-level array and might be processed by Smarty incorrectly (because of too many dots). 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}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.