Is this possible? I’m working on an existing website and I need to overwrite some styles but only on pages that use my new templates as overwriting the main styles might break the other pages. This is the markup:
<div id="page">
<main role="main" id="MainContent">
{{ content_for_layout }}
</main>
{% section 'footer' %}
</div>
So adding a class to the page or main
element would be ideal.
I’ve managed to achieve this with an if
statement to display content but only on a certain template, like this:
{% if template == 'page.job-detail' %}
<!-- CODE HERE -->
{% endif %}
Not sure how that’d work in relation to classes on a div? There’s probably a few pages I’d need to include so an array or a way I was specify multiple templates would be ideal. Templates like “page.faq”, “page.jobs”, “page.job-detail”.
3
Answers
Why don’t you just add a custom class to all of your pages and target that based on the templates you like to target.
So you can add the following to the body tag.
And you will get classes like:
etc..
From there you can use only CSS to style only what you need using the above classes.
In your template name, you can add a string that would give you a hint that it is a custom page like so,
And you can do this to your HTML
Will print template-page-donate for page template with the name "donate"