我正试图在for
循环中将参数传递给液体过滤器,但无法使其正常工作。
在_data
中,我有一个名为fruit_metadata.yml
的文件,其内容如下:
apples:
country: unites states
bananas:
country: brazil
oranges:
country: florida
我想遍历内容并获取每种水果的国家。这是我在做什么:
{% assign fruit = "apples, oranges, bananas" | split: "," %}
{% for item in fruit %}
* doesn't work: {{ site.data.fruit_metadata[item].country }}
* works: {{ site.data.fruit_metadata.apples.country }}
{% endfor %}```
For some reason, `[item]` doesn't seem to be working. The "doesn't work" line returns nothing. The "works" line returns "united states."
How can I pass in `item` here to get the data?
答案 0 :(得分:0)
原来,我只需要删除apples,oranges,bananas
中的空格。