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.

Conditional parsing issue in script tags

February 14, 2012 10:35am

Subscribe [2]
  • #1 / Feb 14, 2012 10:35am

    Joseph Wensley

    38 posts

    I was trying to some conditionals in a script tag in noticed they don’t seem to work properly.

    Template

    <!-- Test 1 -->
     <ścript type="text/javascript">
      {if segment_1 != ""}
       var something == "{segment_1}";
      {/if}
     </ścript>
    
     <!-- Test 2 -->
     <ścript type="text/javascript">
      {if segment_1 != ""}
       var something == "{segment_1}";
      {if:else}
       var something == "";
      {/if}
     </ścript>
    
     <!-- Test 3 -->
     {if segment_1 != ""}
      <ścript type="text/javascript">
       var something == "{segment_1}";
      </ścript>
     {if:else}
      <ścript type="text/javascript">
       var something == "";
      </ścript>
     {/if}

    Output

    <!-- Test 1 -->
     <ścript type="text/javascript">
      var something == "test";
     </ścript>
    
     <!-- Test 2 -->
     <ścript type="text/javascript">
      {if "test" != ""}
       var something == "test";
      {if:else}
       var something == "";
      {/if}
     </ścript>
    
     <!-- Test 3 -->
     <ścript type="text/javascript">
      var something == "test";
     </ścript>


    The 2nd test in there seems to be completely broken, is this a known issue/working as intended or did I just find a new bug?

    This is using EE 2.4.0

  • #2 / Feb 15, 2012 11:53am

    Shane Eckert

    7174 posts

    Hello Joseph,

    Thank you for using the ExpressionEngine forums!

    This is expected behavior because of a Hidden Configuration Variable. protect_javascript defaults to “y”. In order to make the second test work, you will need to add

    $config['protect_javascript'] = 'n';

    to system/expressionengine/config/config.php

    Let me know if this helps or if you have any other questions.

    Cheers,

     

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

ExpressionEngine News!

#eecms, #events, #releases