Question

I'm processing site.posts to compare post.categories against page.categories to create a related posts sidebar but if there are multiple common categories I get multiple links.

I want to break the inner loop but can't find anything to suggest this is possible.

Roughly (because on train and phone) the code I have is

{% for post in site.posts %}
      {% for postcat in post.categories %}
            {% for cat in page.categories %}
                  {% if cat == postcat %}
                        <p> {{ post.title }} </p>
                  {% endif %}
            {% endfor %}
      {% endfor %}
{% endfor %}

Not sure this is even doable

Was it helpful?

Solution

This is more of a Liquid Templating engine question, than a Jekyll one. It appears that Liquid has support for a {% break %} tag which is what you are looking for.

I would suggest making sure your Liquid gem is updated and then try using {% break %} in your code as suggested here.

Possible Duplicate

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top