mdo / jekyll-snippets

Library of commonly used snippets for Jekyll sites.
MIT License
552 stars 23 forks source link

Insert body class #5

Open huphtur opened 9 years ago

huphtur commented 9 years ago

Mind if I contribute the following snippet?

<body class="{% if page.title %}post{% else %}home{% endif %}">

A quick hack to add a class to the body to differentiate between a homepage and post for layout purposes.

XhmikosR commented 9 years ago

This is very specific to your use case and cannot be applied widely.

You could do something like this:

<body{% if page.slug %} class="{{ page.slug }}"{% endif %}>

paired with a replace to handle all cases like spaces etc.

wgallop99 commented 8 years ago

http://joe8bit.com/article/jekyll-generate-body-class

This article was a huge help. A simple ruby plugin that adds a body class to your default template, depending on the title or layout of the page.

damirkotoric commented 4 years ago

Update: that article's URL has moved to: https://joe8bit.wordpress.com/2017/11/02/jekyll-generate-body-class/

And the first line needs to be changed from: class BodyClassTag &lt; Liquid::Tag to: class BodyClassTag < Liquid::Tag