astanush
astanush

Reputation: 413

How do I create an IF statement based on a Jekyll category?

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

Answers (1)

David Jacquel
David Jacquel

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

Related Questions