Jekyll — Change layout if page is a post?

Zaz picture Zaz · Sep 7, 2013 · Viewed 12.9k times · Source

In a Jekyll layout, is there any way to detect if the page is a normal page or a post? I want to display post titles, but not page titles. Like this:

{% if page.is_post? %}
    <h2>{{ page.title }}</h2>
{% endif %}
{{ content }}

Answer

kavinyao picture kavinyao · May 9, 2014

Since Jekyll 2.0, you can use Front Matter Defaults:

defaults:
  -
    scope:
      path: ""      # empty string for all files
      type: posts   # limit to posts
    values:
      is_post: true # automatically set is_post=true for all posts

then you can use {{ page.is_post }} to check whether the page is post.

No idea why Jekyll doesn't set page.type by default.