【发布时间】:2016-10-25 19:48:59
【问题描述】:
我在循环遍历 Drupal 8 中的 html.twig 文件中的简单数据数组时遇到问题。当我将以下块添加到页面时,Drupal 遇到“意外错误”。现在,这对页面来说是静态的也没关系。
注意:我使用 Drupal 和 twig 还不到一周,而我的 PHP 已经生锈了 10 年。
{%
set top_customers = {
{ name: "Altera G", logo: "logo-alterg.png", }
{ name: "Hollywood Was Museum", logo: "logo-hollywoodwaxmuseum.png", }
{ name: "iroaHealth", logo: "logo-iorahealth.png", }
{ name: "Lionel", logo: "logo-lionel.png", }
{ name: "Mashable", logo: "logo-mashable.png", }
{ name: "People Fluent", logo: "logo-peoplefluent.png", }
{ name: "Shop Kick", logo: "logo-shopkick.png", }
{ name: "Wistia", logo: "logo-wistia.png", }
}
%}
{{ dump(top_customers) }}
<section class="row cta-section row-padding-130">
<div class="row-inner site-width">
<div class="brick-10 center-brick">
<h3>These brands are changing the way they think about AP by using MineralTree</h3>
</div>
<div class="brick-12 center-brick">
<ul class="logo-list margin-top-78 clearfix">
{% for customer in top_customers %}
<li>
<img class="customer-logo img-fluid" src="{{ directory }}/images/customer-logos/{{ customer.logo }}" alt="{{ customer.name }}" />
</li>
{% endfor %}
</ul>
</div>
<div class="brick-6 center-brick">
<div class="margin-top-78">
<a href="/about-us/our-customers.html" class="solid-cta-btn button-large">view all our customers</a>
</div>
</div>
</div>
</section>
感谢您的帮助!
【问题讨论】:
-
你还有这个错误吗?当我们不知道在哪里寻找时,很难开始。
-
最近的日志消息显示:“Twig_Error_Syntax:哈希键必须是带引号的字符串、数字、名称或括号中的表达式(值“{”的意外标记“标点符号”在“主题/自定义/mineraltree/templates/region--banner5.html.twig”在第 4 行。在 Twig_ExpressionParser->parseHashExpression() (/Applications/MAMP/htdocs/mineraltree/vendor/twig/twig/lib/Twig 的第 281 行/ExpressionParser.php)。”