I'm needing to add a class to the body tag based on what page is currently active. Can this be done with Grav?
I need help with this too, specially how to capture he header title as body class
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
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">
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.
Log in to reply.
Suggested topics
| Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| 0 | 1361 | 9 years ago | ||
| 2 | 939 | 9 years ago | ||
| 2 | 4069 | 9 years ago | ||
| 1 | 2958 | 9 years ago | ||
| 3 | 1123 | 9 years ago |