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.

channel fields within javascript

July 23, 2012 9:44am

Subscribe [1]
  • #1 / Jul 23, 2012 9:44am

    jackiewales

    37 posts

    This works fine:

    {exp:channel:entries channel="mychannel" limit="1" url_title="{segment_3}"}
    $.dpSocialBar(
    {
        items: {
                                        twitter: { url: '{twittermember}', text: '{title} on twitter' },
        },
    
       });
     {/exp:channel:entries}

    ie the channel fields twittermember and title are made available to the javascript. If I include a conditional to test for the field it breaks

    {exp:channel:entries channel="mychannel" limit="1" url_title="{segment_3}"}
    $.dpSocialBar(
    {
        items: {
                                        {if twittermember !=""}
                                        twitter: { url: '{twittermember}', text: '{title} on twitter' },
                                        {/if}
        },
    
       });
     {/exp:channel:entries}


    I’ve just noticed this post, http://ellislab.com/forums/viewthread/200960/ . John says you cannot use ee conditionals within javascript in which case how can I test for the existence of the ee field?

     

  • #2 / Jul 23, 2012 10:55am

    jackiewales

    37 posts

    Managed to sort this one!  Apparently advanced conditionals within javascript blocks do not get parsed,  To turn this off you enter the following in ee/config/config.php:
    $config[‘protect_javascript’] = ‘n’;

  • #3 / Jul 23, 2012 6:25pm

    Kevin Smith

    4784 posts

    Glad to see you resolved it, jackiewales. If there’s anything else I can help with, please just let me know!

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

ExpressionEngine News!

#eecms, #events, #releases