Liang
Liang

Reputation: 1187

How can jekyll judge whether it is a page or a post?

I want to add a class to the body tag using if sentence, if the page is a post then add page to the class if the page is a post then add post to it. I don't know in specific how to do this, can anyone help me figure it out?

Upvotes: 9

Views: 1468

Answers (1)

huon
huon

Reputation: 102216

You can test for the presence of page.date or page.id, e.g.

<div class="{% if page.id %} post {% else %} page {% endif %}">
   ...
</div>

Upvotes: 16

Related Questions