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

Add class to the body/html when on error page

Started by Muut Archive 10 years ago · 2 replies · 426 views
10 years ago

How to add class to the body when user is on particular page? In my case this is "error" page (404/403 etc.)

10 years ago

I should add that I want to do it for .twig page, not .md page.

10 years ago

Solved it! In case someone is looking for same solution:

In my base.html.twig I have:

TWIG
{% block body %}
<body>
{% endblock %}

In my error page error.html.twig I defined a class that will be added to the body everytime browser display error page:

TWIG
{% block body %}
<body class="error-page">
{% endblock %}

And then I target in CSS:

TXT
body.error-page { 
 // your css
}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1368 9 years ago
Archive · by Muut Archive, 9 years ago
2 940 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1125 9 years ago