ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Passing ExpressionEngine Variables to Javascript

February 18, 2009 5:58pm

Subscribe [2]
  • #1 / Feb 18, 2009 5:58pm

    Todd D.

    460 posts

    I don’t feel right posting this in the tech support forums as it’s not really a core EE function… but rather something somewhat outside the box.

    I have a javascript file that I would like to pass three EE variables to. I don’t care if the js file is linked to outside the system or even if it resides as a EE js template.  What I don’t want to do is turn off javascript protection in the entire system for EE to parse the js template and pick up the variables.

    Has anyone been able to use a javascript file or template with variables passed from the EE system without turning off js protection? And IF so… what approach did you use?

    Thanks for any ideas on this one!

  • #2 / Feb 20, 2009 10:32am

    Matthew Pennell

    221 posts

    Why don’t you just assign the JavaScript variables in the relevant template:

    // Opening script tag goes here
    var foo = "{foo}", bar = "{bar}";
    // Closing script tag goes here

    And then link to an external script file at the bottom of your template that references those global variables?

    (Edit: the forum removed my script tags)

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases