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

Adding body classes to a template that inherits

Started by Muut Archive 11 years ago · 3 replies · 467 views
11 years ago

I'm making a theme that inherits from antimatter, and the templates inherit from base.html.twig.

I'd my template "has-header" to add classes to the <body> element, as if all pages using that template also defined "body_classes" in their yaml frontmatter.

Is there a nice way to do this without duplication? Apologies for such a simple question!

11 years ago

you would have to override the templates/partials/base.html.twig in your template to add that logic to the <body> element.

11 years ago

Is there a variable "page.template"? Would I write something along the lines of:

<body id="top" class="{% if page.template == 'has-header' %} header-image fullwidth {% endif %}">

11 years ago

(oh! the answer is literally yes. Thanks for all your help, you're fantastic)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1330 9 years ago
Archive · by Muut Archive, 9 years ago
2 922 9 years ago
Archive · by Muut Archive, 9 years ago
2 4051 9 years ago
Archive · by Muut Archive, 9 years ago
1 2930 9 years ago
Archive · by Muut Archive, 9 years ago
3 1108 9 years ago