We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26401
    • 247 Posts
    I tried looking for information on this, but haven’t had much luck finding it.

    I am wonderingwhatthe best practices are for implementing java scripts

    if I have a .js file, where is a good place to put it
    where in the file should I included it
    should I be using chunks ?
    do I need to include it in the template ?


    any help on this would be great...
    thanks in advance
      • 4310
      • 2,310 Posts
      You can put it anywhere but there is a folder assets/js/ already.
      If you need it for all pages using a particular template then include it in the <head> of the template like this..
      <script type="text/javascript" src="assets/js/yourJSscript.js"></script>

      Always good to have this in the <head> as well
      <base href="[(site_url)]"></base>

      You can also use it in many other ways via chunks, TV’s etc.
        • 26401
        • 247 Posts
        thanks ...
        I’m assumng I should create a new template for the sites that will use javascript
          • 4310
          • 2,310 Posts
          You could have a different template for the pages needing JS.
          Or you could create a TV named "javascript".
          Give your template access to it.
          Add [*javascript*] to the <head> of your template.
          Then on the pages that need the JS add the link or actual JS it to the "javascript" TV.
          That way you don’t need another template, that’s why their called Template Variables and why they’re so useful!