Add class to elements based on items inside of for loop in Jekyll

Viewed 39

I have a simple for loop that pulls from a JSON file in my _data folder. I want to be able to add a class to all the H1s if there are more than 3 titles and remove the class if there are less than 3 titles. I tried using conditional logic but doesn't seem to add the class to everything.

{% for book in site.data.books limit: 6 %}
    If > 3
        <h1 class="BookTitle {% if book.title > 3 %}BookTitleAlt{% endif %}>{{ book.title }}</h1>
    If < 3
        <h1 class="BookTitle">{{ book.title }}</h1>
{% endfor %}
1 Answers
Related