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.

problem with conditionals

May 06, 2011 9:13am

Subscribe [3]
  • #1 / May 06, 2011 9:13am

    mark59

    88 posts

    Hi

    I have a section of my template trying to define some javascript to be output based on channel content. Some of it should only appear conditionally within the javascript section - so for example i have in my template

    <sscript type="text/javascript">
    
    function initialize() {
    
    {exp:channel:entries channel="dealers" }
    
    {if count == 1}
    
    // do something
    
    {/if}
    
    {/exp:channel:entries}
    
    </sscript>

    - however the conditionals within the channel tag pair do not work and instead I get for example being output

    <sscript type="text/javascript">
    function initialize() {
    {if "1" == 1}
    // do something 
    {/if}
    </sscript>

    so instead of the conditionals being evaluated within the template - I get

    {if "1" == 1}

    and

    {/if}

    appearing in the HTML code - how do I fix this ?

    The parsing of the template must somehow think my conditionals are not EE conditionals

    Note the spelling of script as sscript in the tag above is purely so the code displays here in this forum entry

  • #2 / May 06, 2011 10:39am

    metadaptive

    96 posts

    Hi mark59

    I reckon you likely want to add:

    $conf[‘protect_javascript’] = ‘n’;

    to config.php

    See here for details: http://expressionengine.com/wiki/Hidden_Configuration_Variables#protect_javascript

  • #3 / May 06, 2011 10:49am

    mark59

    88 posts

    Hi mark59

    I reckon you likely want to add:

    $conf[‘protect_javascript’] = ‘n’;

    to config.php

    See here for details: http://expressionengine.com/wiki/Hidden_Configuration_Variables#protect_javascript

     

    Many Thanks metadaptive

    That has solved my issue and my conditionals are now being evaluated and the output is correct.

    Thank you again

  • #4 / May 06, 2011 10:59am

    metadaptive

    96 posts

    any time mate - that caught me out first time too 😉

    it’s well worth digging into the config.php options - there’s all sorts of useful stuff in there…

  • #5 / May 06, 2011 7:38pm

    Sue Crocker

    26054 posts

    Thanks for the assist, metadaptive.

    mark59 - Feel free to start a new thread if you have any more questions.

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

ExpressionEngine News!

#eecms, #events, #releases