Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Body Class

Started by Muut Archive 11 years ago · 4 replies · 1023 views
11 years ago

I'm needing to add a class to the body tag based on what page is currently active. Can this be done with Grav?

11 years ago

I need help with this too, specially how to capture he header title as body class

11 years ago

figured it out, change:
<body class="{% block body_classes %},{{ page.header.body___class }},{% endblock %}"> to
<body class="{% block body_classes %},{{ page.header.title }},{% endblock %}">
in base.html.twig

11 years ago

Another option: You can keep _body__class in the base.html.twig and add body_class: class-name to the front-matter of any markdown page you wish to target with body class css.

Your source html wiill output: <body class="class-name">

11 years ago

Yup, just depends on whether or not the theme you are using has that body_class being output in the body tag. There are no theme requirements as such for Grav, you can do whatever you like, themes that used Antimatter as a starting point, probably have that, but if not, it's simple enough to add.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Muut Archive, 10 years ago
1 674 1 week ago
Archive · by Deleted User, 9 years ago
0 3043 9 years ago
Archive · by Muut Archive, 9 years ago
2 1983 9 years ago
Archive · by Muut Archive, 9 years ago
2 5337 9 years ago
Archive · by Muut Archive, 9 years ago
1 4134 9 years ago