Meteor - change content of HTML <head> section for different templates?

I have a scenario where I want to test four different versions of a page, each with different javascript content loaded into the HTML head section.

I would like to switch between templates to behave as if the page were reloaded, clearing the state and rerunning the JS in the head and in the body of the HTML file.

Can I do this with four different Meteor templates?

+3


source share


1 answer


The way I would go about it is add JS to the head from the onRendered template like:

Template.templateName.onRendered(function() {
  $('head').append("insert your script here");
});

      



So, I would keep the default head without any of these js files and just add them depending on which template the user is enabled for. You can also manipulate the UI inside the onRendered method using things like $(window).scrollTop(0)

to make it look as if the page has been refreshed.

+3


source







All Articles