Dan Hennion
Dan Hennion

Reputation: 1745

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.

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'

My code for page.blogtags.liquid is as follows:

<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.

What am I doing wrong?

Upvotes: 0

Views: 1358

Answers (1)

Bilal Akbar
Bilal Akbar

Reputation: 4930

You are just missing quotes around recipes. Currently, Liquid is treating recipes as a variable and since it is undefined, it silently fails. All you needs is 'recipes' or "recipes" to specify that you want to access blogs property named 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

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

Upvotes: 1

Related Questions