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.

Testing for variable set to false crashes a template

March 16, 2011 2:45pm

Subscribe [4]
  • #1 / Mar 16, 2011 2:45pm

    Napco

    19 posts

    When myvar is set, this does not work.

    {if myvar}DO STUFF{/if}

    However with the following…

    {if {myvar}}DO STUFF{/if}

    When myvar is set to an empty string or false it causes the template to stop rendering and outputs the following error:

    Parse error: syntax error, unexpected ‘)’ in /home/admintel/public_html/ee/ee_sys/core/core.functions.php(637) : eval()‘d code on line 115

    Fatal error: Call to undefined function ob_end() in /home/admintel/public_html/index_to_include.php on line 217

    ExpressionEngine 1.6.7
    Build:  20090320

  • #2 / Mar 17, 2011 9:32am

    Sue Crocker

    26054 posts

    Hi, Napco.

    Try the following for testing for an empty value…

    {if myvar!=""}DO STUFF{/if}

    Does that work for you? Also, we do recommend you upgrade to EE1.7.0 since it’s a security upgrade.

  • #3 / Mar 18, 2011 2:25pm

    Napco

    19 posts

    {!--That does work thanks. Can't have any spaces between the operator and the operands.--}

    Wait. Not it doesn’t. The page executes, but myvar!==”” returns true when myvar is an empty string anyway.

    ????

  • #4 / Mar 18, 2011 4:28pm

    Sue Crocker

    26054 posts

    You need != not !== give that a try.

  • #5 / Mar 18, 2011 5:22pm

    Napco

    19 posts

    {quantcast}
    {if {quantcast}!=''}Singles - With Braces{/if}
    {if quantcast!=''}Singles - Without Braces{/if}
    {if {quantcast}!=""}With Braces{/if}
    {if quantcast!=""}Without Braces{/if}

    Running that code merely outputs the value of the {quantcast} variable. It has a value, yet NONE of the preceding four conditionals yield any output.

  • #6 / Mar 20, 2011 3:24pm

    Greg Salt

    3988 posts

    Hi Napco,

    What populates this variable and what is its exact content? Please make sure that you leave a space between the variable and the comparator:

    {if quantcast != ''}...code…{/if}

    Cheers

    Greg

  • #7 / Mar 21, 2011 10:47am

    Napco

    19 posts

    <?php
    
        $vars = array('page_title'=>'Some Web Page', 'quantcast'=>'Quantast ID');
        
        foreach ($vars as $name=>$value) {
            echo '{assign_variable:'. $name .'="'. $value .'"}';
        }
    ?>
    {page_title}
    {if page_title != ''}There was a page title{/if}
    {if comscore != ''}There was a Comscore ID{/if}

    This is a cursory example of the code. The template is set to execute PHP on input.

    The output of the above is simply “Some Web Page” due to the use of the {page_title} variable. However the conditionals return false despite the variable holding content.

  • #8 / Mar 21, 2011 1:03pm

    Napco

    19 posts

    I can move the logic to PHP, but this still makes no sense to me.

  • #9 / Mar 22, 2011 5:49am

    John Henry Donovan

    12339 posts

    Napco,

    Your issue is parse order. Simple conditionals are parsed after PHP so that is never going to evaluate

    What are you trying to achieve ? There may be an easier way. Without using PHP at all

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

ExpressionEngine News!

#eecms, #events, #releases