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.

What's the best way to add Javascript variables into my EE tags? (without them being seen as a string)

February 24, 2011 12:21am

Subscribe [2]
  • #1 / Feb 24, 2011 12:21am

    brianearwood

    40 posts

    Hi everyone,

    I’ve got multiple (image gallery) channel entries set up with to store multiple images (using Matrix). In my Javascript template, I want to query the entries to pull all of the image data and push each image into an array. From there, the array will be fed into my gallery rotator.

    1. The site visitor will click a button to load a set of gallery images (which is one channel entry).
    2. jQuery will pull the {entry_id} out of the button html.
    3. The {entry_id} number will be stored in a javascript variable.
    4. A EE channel:entries tag in the javascript will query the same channel, using the {entry_id} variable to know which entry to pull from.
    5. Each image gets pushed into an array.

    The part that is tripping me up is the EE channel:entries tag using the {entry_id} variable, since the ”  entry_id=’  ’  ” part of the EE tag converts the variable to a string.

    Is there an easy way to do this without getting into storing the numbers in PHP or is PHP the only way to pull that off?

    here’s the code:

    nav.click(function(e) {
        var $target = $(e.target);
        var entryId = $target.attr('rel');
        
            {exp:channel:entries channel='gallery-couple' entry_id=' ' }
            var galleryImages = [
                    
                //push images into array
                    
            ];
        {/exp:channel:entries}
    });

    Thanks for the help!
    -B

  • #2 / Feb 24, 2011 9:10am

    the3mus1can

    426 posts

    You are probably going to have to rethink the flow of events here.  The javascript will not be able to execute the EE tags.  It would probably be best for the javascript to make an Ajax call to a template that returns the image data that you need.

  • #3 / Feb 24, 2011 11:47am

    brianearwood

    40 posts

    I was fiddling around with something last night where I had a separate javascript template named images.js. I used a single EE channel:entries tag to build a json tree of all of my images.  Does that sound like a way to go?

    B

  • #4 / Feb 24, 2011 8:57pm

    the3mus1can

    426 posts

    That can work too.

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

ExpressionEngine News!

#eecms, #events, #releases