Why the variable in the template ?

Why do we need this variable in this template :

{% set template_css = “../../css/templates/blog.css” %}

It loads css specific to that template. You’ll find the file at [your-theme]/css/templates/blog.css


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

But can’t we just have it in another file ? Must it be in the template for
it to load ?

The css is in another file.

It’s only used by that specific template so it’s only called by that template. Otherwise you’d be calling it on pages that don’t need it and that’d add to load time unnecessarily.

Edit: slight correction, I’m assuming this is the boilerplate/a theme based on the boilerplate. blog.css is used in both the blog-index template and the blog-post template, but the reasoning would be the same. I am also assuming that’s why it’s loaded like that but it would stand to reason.


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

Sorry Barry … but I’m still not getting it .

How is it being called in the template?

What’s the syntax of calling a css file to only a specific template ?

Thanks !

You can demo it pretty simply by going into the blog.css file and adding some css.

I added this to mine:

h1 {
 color: purple !important;
}

and the h1 tags on my blog became purple.

You can also see that if you remove

{% set template_css = "../../css/templates/blog.css" %}

from your template, the css contained in blog.css no longer applies to any pages using that template.


Barry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn