【发布时间】:2017-08-20 14:04:41
【问题描述】:
我尝试在 include 的 var 中传递一个数组元素。
但我仍然有这个错误:
致命错误:未捕获 --> Smarty 编译器:模板“file:/home/technique/www/site/tpl/home.html”第 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'}" - 意外的 ".",预期为其中之一: "}"
我的代码:
{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}
显然,问题在于使用常量 ARTICLE_CATEGORY。看来 php 常量没有被 smarty 解释......
【问题讨论】:
-
要访问 Smarty 中的 PHP 常量,您可以使用 {$smarty.const.MY_CONSTANT} 即smarty.net/docs/en/…