We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23849
    • 223 Posts
    thefutureforward Reply #1, 17 years ago
    Hi All,

    I’m needing to call template variables from WITHIN a javascript file. Here was my attempt:

    function swapSanFrancisco() {
       document.getElementById('map').src = "img/map-sanfrancisco.gif";
       document.getElementById('chapterInfo').innerHTML = '[*sanFrancisco*]';
       return(false);
    }
    


    Basically, when you click a link on my page it’s replacing the HTML of a div on that page with some new text. Unfroatunately, when I call the TV from within my javascript file it’s just showing the text [*sanFrancisco*] rather than actually interpreting that as a template variable.

    Does anyone know how to call a TV from within a javascript file and have it interpret correctly as a TV? Let me know, thanks!
      Nick Hoag
      Creative Partner
      The FutureForward

      http://thefutureforward.com
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: presson83 at Sep 23, 2009, 10:56 AM

      Hi All,

      I’m needing to call template variables from WITHIN a javascript file. Here was my attempt:

      function swapSanFrancisco() {
         document.getElementById('map').src = "img/map-sanfrancisco.gif";
         document.getElementById('chapterInfo').innerHTML = '[*sanFrancisco*]';
         return(false);
      }
      


      Basically, when you click a link on my page it’s replacing the HTML of a div on that page with some new text. Unfroatunately, when I call the TV from within my javascript file it’s just showing the text [*sanFrancisco*] rather than actually interpreting that as a template variable.

      Does anyone know how to call a TV from within a javascript file and have it interpret correctly as a TV? Let me know, thanks!
      You would have to have the Javascript in the content of a MODx Resource in <script> tags, or by serving your Javascript file as a separate Resource itself, in which case the TV would have to be attached to it.
        • 23849
        • 223 Posts
        thefutureforward Reply #3, 17 years ago
        Hi Jason,

        Thanks so much for the response. I ended up finding a different solution for this particular issue, but I will definitely keep that in mind in the future. Thanks again!
          Nick Hoag
          Creative Partner
          The FutureForward

          http://thefutureforward.com