How do I set Javascript variables using perch?

  • 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:


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

    And the template can be:


    Code
    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