我正在Jekyll写一个使用Liquid的网站 .
我有前面的问题,我希望看起来像这样:
---
title: Designing algorithms that scale horizontally
speaker: Luke Ehresman, CopperEgg
category: notes.mongodallas.talks
links:
- demo: http://www.github.com/copperegg/mongo-scaling-demo
layout: talknotes
---
在Liquid中,YAML的链接部分来自:
[{'demo' => 'http://www.github.com/copperegg/mongo-scaling-demo' }]
我希望能够迭代数组,做这样的事情:
<a href="{{ link.value }}">{{ link.key }}</a>
但到目前为止,我所有的想法都让我失望了 .
3 回答
当您使用名为
hash
的变量迭代哈希时,hash[0]
包含密钥,hash[1]
包含每次迭代的值 .我会在YAML中定义它们:
然后迭代:
我有一个非常相似的问题,但我的变量中有多个项目,所以我使用了未记录的
item
变量,它完成了工作 .