Open huphtur opened 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.
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.
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 < Liquid::Tag
to:
class BodyClassTag < Liquid::Tag
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.