我的 Grav/Twig 模板有一个简单的问题。我有一个 .md 文件,其结构如下......
---
class: news
title: Latest News
story:
title: TITLE OF STORY
date:
month: April
day: 2
year: 2016
highlights:
points:
- icon: mic.png
text: Best Speaker Award
- icon: trophy.png
text: Winner as voted by audience
quote:
text: “Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur dictum nisl quis pharetra dictum. Etiam ac egestas leo. Pellentesque tincidunt sem vel risus vehicula scelerisque. Cras rutrum, mauris viverra porttitor condimentum, orci quam condimentum libero, ac tempor nunc risus ac felis.”
author: -Time Magazine
cite: http://www.time.com
image: awards.jpg
---
我想拉出图标:mic.png 和图标:trophy.png 值并在我的 news.twig.html 文件中执行类似的操作...
<div class="highlights">
{% for highlight in page.header.story.highlights.points %}
<div class="point">
{% if highlight.text %}
<span class="highlight-icon">
<img src="{{ page.media.images.[ {{ highlight.icon }} ].url }}">
</span>
{% endif %}
{% if highlight.text %}
<span class="highlight-text">{{ highlight.text }}</span>
{% endif %}
</div>
{% endfor %}
但是我收到一个错误,“预期的名称或号码”在带有 img 标签的行上,
<img src="{{ page.media.images.[ {{ highlight.icon }} ].url }}">
先感谢您!!