gpt4 book ai didi

json - 尝试实现 amp-mustache 时出错

转载 作者:行者123 更新时间:2023-12-04 23:40:35 24 4
gpt4 key购买 nike

我正在尝试复制 this example没有成功。我想使用 mustache 添加一个列表模板,像这样:

<ul>
<amp-list width=auto
height=100
layout=fixed-height
src="/assets/popular.json">
<template type="amp-mustache"
id="amp-template-id">
<li>
<a href={{url}}>{{title}}</a>
</li>
</template>
</amp-list>
</ul>

我的 /assets/popular.json文件是:
{
"items": [
{
"title": "amp-carousel",
"url": "https://ampbyexample.com/components/amp-carousel"
},
{
"title": "amp-img",
"url": "https://ampbyexample.com/components/amp-img"
},
{
"title": "amp-ad",
"url": "https://ampbyexample.com/components/amp-ad"
},
{
"title": "amp-accordion",
"url": "https://ampbyexample.com/components/amp-accordion"
}
]
}

但我无法让它工作, json 中的值没有在模板中被替换,我收到此错误:
Missing URL for attribute 'href' in tag 'a'

不知道为什么值 {{url}}没有被 json 的内容正确替换.

我添加了必要的 scripts在头部。

最佳答案

最近我一直在迁移到雨果 来自 杰基尔 并面临同样的问题。以下是两者的解决方案。
杰基尔
现在解决了,问题是我正在使用 jekyll ,等等标签 {{tag}} 被解释为 liquid tag .我解决了它写这样的代码:

<ul>
<amp-list width=auto
height=100
layout=fixed-height
src="/assets/popular.json">
<template type="amp-mustache"
id="amp-template-id">
<li>
<a href="{% raw %}{{url}}{% endraw %}">{% raw %}{{title}}{% endraw %}</a>
</li>
</template>
</amp-list>
</ul>
更新 : 我写了一个 more detailed explanation
雨果
<ul>
<amp-list width=auto
height=100
layout=fixed-height
src="/assets/popular.json">
<template type="amp-mustache"
id="amp-template-id">
<li>
<a class="card related" id={{"{{id}}"}} {{ printf "href=%q" "{{url}}" | safeHTMLAttr }}>
{{"{{title}}"}}
</a>
</li>
</template>
</amp-list>
</ul>

关于json - 尝试实现 amp-mustache 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38672182/

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