I'm using Mozilla Nunjucks templating system for a static website which has multiple pages. For some purpose, I want to add a class to body
tag for each different page
About us page > <body class="about">
Home > <body class="home">
I can do this very easily if body
tag I keep inside every page but I want to keep body
tag inside my template which I would be using for all pages.
I want to change classes conditionally.
{% set bodyClass = "pageClass" %}
<body{% if bodyClass %} class="{{ bodyClass }}"{% endif %}>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With