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.

PHP error on EE code

March 16, 2009 9:12am

Subscribe [2]
  • #1 / Mar 16, 2009 9:12am

    dolmance

    101 posts

    Hello, I am getting wrong PHP values when I use EE conditionals. For example:

    <? $var="0" ?>
    {exp:weblog:entries weblog="1"}
        {categories}
            {if category_name=="Books"}
            <? $var="1" ?>
            {if:else}
            <? $var="2" ?>
            {/if}
        {/categories}
    <? echo $var; ?>
    {/exp:weblog:entries}

    It always renders 2. Instead, this code:

    <? $var="0" ?>
    {exp:weblog:entries weblog="1"}
        {categories}
            {if category_name=="Books"}
            <? $var="1" ?>
            {if:else}
    
            {/if}
        {/categories}
    <? echo $var; ?>
    {/exp:weblog:entries}

    It always renders 1.My PHP setting is Output parsing, so I guess EE is not respecting my PHP code.

    Thank you.

  • #2 / Mar 16, 2009 10:37am

    Ingmar

    29245 posts

    You cannot mix EE and PHP tags like that. Or, rather, you cannot use EE conditionals to decide which parts of your PHP code will be run. All PHP will always be executed: the conditionals only decide which part of your template to display in the final template. If you need that level of flexibility, use PHP for the conditional as well.

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

ExpressionEngine News!

#eecms, #events, #releases