[英]Shopify List Blog Tags
我正在尝试在 Shopify 中创建一个页面,该页面循环遍历分配给名为“食谱”的博客中的博客文章的所有标签,并简单地列出所有标签。
这看起来很简单,但我的页面没有输出任何标签。
-我创建了一个名为“食谱”的博客
- 我将博文分配给“食谱”博客,并且每一篇都分配了不同的标签。
-我创建了一个模板 (page.blogtags.liquid),并将该模板分配给名为“博客标签”的页面
我的 page.blogtags.liquid 代码如下:
<div id=”blog-tags”>
<!– Loops over all the tags used in Recipes blog –>
{% for tag in blogs[recipes].tags %}
<h2>{{ tag }}</h2>
{% endfor %}
</div>
该页面正在输出 div,但它不包含任何内容。
我究竟做错了什么?
您只是缺少recipes
周围的引号。 目前,Liquid 将recipes
视为一个变量,由于它未定义,因此它会默默地失败。 您只需要'recipes'
或"recipes"
来指定您要访问名为recipes
的博客属性。 所以代码会变成
<div id=”blog-tags”>
<!– Loops over all the tags used in Recipes blog –>
{% for tag in blogs['recipes'].tags %}
<h2>{{ tag }}</h2>
{% endfor %}
</div>
或者,您也可以做blogs.recipes.tags
<div id=”blog-tags”>
<!– Loops over all the tags used in Recipes blog –>
{% for tag in blogs.recipes.tags %}
<h2>{{ tag }}</h2>
{% endfor %}
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.