How to use variable in a jekyll liquid loop?

For example,

{% assign tech = technology %}

now I made some post with the category technology. Now I want to loop them like this

                      {% for post in %}
                      {% endfor %}

If I do the same procedure but specify the category fully “technology” it works. But whenever I use the variable “tech” it doesn’t work

Please help

Using Liquid, you think about what you need first, which in your case is post.title. That title lives in site.posts, so you start by creating an array of posts. When creating the array, you add a filter to inform Jekyll what content you are looking for by using a where or where_exp filter.

Here is what your final code might look like:

{%- assign posts = site.posts | where_exp: 'post', 'post.category == tech' -%}
{% for post in posts %}
    <p>Title = {{post.title}}
{% endfor %}
1 Like