Loading Javascript files based on specific pages

SOLVE
lica-mm
Participant | Diamond Partner

Hi All,

I apologize if this has been discussed and answered elsewhere.

We are currently building out a theme (not a template) and are stuck on what the best practices are to load javascript files to specific pages.

 

In the old template structure, extra javascript files could be attached by the end-user (which was mostly us) when we were setting up the landing pages, but in the new theming structure, only css files can be attached/overridden.

 

Am I correct to assume that the "additional code snippets" are supposed to be used to add additional javascript files to the page? 

Skiier, surfer, dog lover.
0 Upvotes
1 Accepted solution

Accepted Solutions
Indra
Solution
Top Contributor | Diamond Partner

Hi @lica-mm,

 

With theme development I think it's best to enbed scripts by template. You could check the HubSpot CMS Boilerplate. Within a theme you can create multiple templates. So if you need to embed scripts within landingpages, it's best to create a custom template for landingpages and add these scripts to that specific template.

 

If you have multiple landingpages but only want to load script on specific pages and not all landingpages, this should be content related. If this is so, then you still can create custom modules and attatch custom scripts inside the custom module or attach it to the custom module.

 

Hope this helps developing your theme.

If you have any thoughts about it, let me know.


Bureau Vet

Did my post solve your question? Help the community by marking it as a solution

View solution in original post

1 Reply 1
Indra
Solution
Top Contributor | Diamond Partner

Hi @lica-mm,

 

With theme development I think it's best to enbed scripts by template. You could check the HubSpot CMS Boilerplate. Within a theme you can create multiple templates. So if you need to embed scripts within landingpages, it's best to create a custom template for landingpages and add these scripts to that specific template.

 

If you have multiple landingpages but only want to load script on specific pages and not all landingpages, this should be content related. If this is so, then you still can create custom modules and attatch custom scripts inside the custom module or attach it to the custom module.

 

Hope this helps developing your theme.

If you have any thoughts about it, let me know.


Bureau Vet

Did my post solve your question? Help the community by marking it as a solution

View solution in original post