CMS Development

DOchieng
Participant

Why the variable in the template ?

Why do we need this  variable in this template  :

 

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

 

Screenshot (3).png

0 Upvotes
5 Replies 5
BarryGrennan
Top Contributor

Why the variable in the template ?

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.

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

 

 

 

BarryGrennan
Top Contributor

Why the variable in the template ?

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.

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

 

 

DOchieng
Participant

Why the variable in the template ?

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 !

0 Upvotes
BarryGrennan
Top Contributor

Why the variable in the template ?

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

 


profile2022aBarry Grennan

Freelance HubSpot CMS Developer

Website | Contact | LinkedIn

 

 

DOchieng
Participant

Why the variable in the template ?

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