Reputation: 413
I want to conditionally add a class to <body>
if a post is in the "article" category. I tried the following:
<body
{% if page.categories == article %}
class="article"
{% endif %}
>
Strangely, this places the "article" class on every page except article posts.
Upvotes: 1
Views: 1863
Reputation: 52829
Use contains
:
<body {% if page.categories contains "jekyll" %} class="article"{% endif %}>
All on one line otherwise you will have line breaks in your tag.
Upvotes: 6