简体   繁体   English

Shopify 列表博客标签

[英]Shopify List Blog Tags

I'm trying to create a page in Shopify that loops through all the tags assigned to blog articles in a blog called 'Recipes', and simply list them all.我正在尝试在 Shopify 中创建一个页面,该页面循环遍历分配给名为“食谱”的博客中的博客文章的所有标签,并简单地列出所有标签。

This seems simple, but my page is not outputting any tags.这看起来很简单,但我的页面没有输出任何标签。

-I have a blog created called 'Recipes' -我创建了一个名为“食谱”的博客

-I have blog posts assigned to the 'Recipes' blog, and each one has a different tag assigned. - 我将博文分配给“食谱”博客,并且每一篇都分配了不同的标签。

-I created a template (page.blogtags.liquid), and assigned that template to a page called 'Blog Tags' -我创建了一个模板 (page.blogtags.liquid),并将该模板分配给名为“博客标签”的页面

My code for page.blogtags.liquid is as follows:我的 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>

The page is outputting the div, but it contains nothing.该页面正在输出 div,但它不包含任何内容。

What am I doing wrong?我究竟做错了什么?

You are just missing quotes around recipes .您只是缺少recipes周围的引号。 Currently, Liquid is treating recipes as a variable and since it is undefined, it silently fails.目前,Liquid 将recipes视为一个变量,由于它未定义,因此它会默默地失败。 All you needs is 'recipes' or "recipes" to specify that you want to access blogs property named recipes .您只需要'recipes'"recipes"来指定您要访问名为recipes的博客属性。 So the code would become所以代码会变成

<div id=”blog-tags”>
    <!– Loops over all the tags used in Recipes blog –>
    {% for tag in blogs['recipes'].tags %}
        <h2>{{ tag }}</h2>
    {% endfor %}
</div>

Alternatively, you can also do blogs.recipes.tags或者,您也可以做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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM