How do I set Javascript variables using perch?

  • I have a JS file, call it test.js.

    Inside of it, I have a bunch of variables.

    var heading = "Name";

    var body = "Text";

    I would like to set the variable names using Perch.

    Is that possible? If so, how?

  • drewm

    Approved the thread.
  • You can create a new region in an inline script tag on the page just before you reference the test.js and have php render what you need. Ex:

    1. <script>
    2. <?php perch_content(“JsVars”); ?>
    3. </script>
    4. <script src=“test.js” ></script>

    And the template can be:

    1. var test1 =“<perch:content id=“my_var” type=“text” />”;

    This is just one way, but it works. Sorry if I messed up some pseudo code here, I’m on my phone.8o