gpt4 book ai didi

liquid - 迭代液体模板中的哈希值

转载 作者:行者123 更新时间:2023-12-03 06:30:08 36 4
gpt4 key购买 nike

我正在 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>

但是到目前为止我的所有想法都失败了。

最佳答案

当您使用名为 hash 的变量迭代哈希时,hash[0] 包含 key ,hash[1] 包含每次迭代的值。

{% for link_hash in page.links %}
{% for link in link_hash %}
<a href="{{ link[1] }}">{{ link[0] }}</a>
{% endfor %}
{% endfor %}

关于liquid - 迭代液体模板中的哈希值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8206869/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com