我无法在Drupal 8的html.twig文件中循环浏览我希望的简单数据数组。当我将下面的块添加到页面时,Drupal会遇到&#34 ;意外错误"。现在可以,这对页面来说是静态的。
注意:我进入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>
感谢您的帮助!
答案 0 :(得分:1)
尝试将top_customers
定义为数组,如下所示:
{%
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", },
]
%}
Here一个工作示例