jekyll-snippets icon indicating copy to clipboard operation
jekyll-snippets copied to clipboard

Insert body class

Open huphtur opened this issue 10 years ago • 3 comments

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.

huphtur avatar Jan 16 '15 14:01 huphtur

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.

XhmikosR avatar Jan 24 '15 12:01 XhmikosR

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.

wgallop99 avatar May 13 '16 18:05 wgallop99

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

damirkotoric avatar Nov 28 '19 10:11 damirkotoric