Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Body Class

Started by Muut Archive 10 years ago · 4 replies · 792 views
10 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?

10 years ago

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

10 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

10 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">

10 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 Deleted User, 9 years ago
0 1360 9 years ago
Archive · by Muut Archive, 9 years ago
2 938 9 years ago
Archive · by Muut Archive, 9 years ago
2 4068 9 years ago
Archive · by Muut Archive, 9 years ago
1 2958 9 years ago
Archive · by Muut Archive, 9 years ago
3 1122 9 years ago