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.

Conditionals not working properly

October 27, 2010 5:27pm

Subscribe [2]
  • #1 / Oct 27, 2010 5:27pm

    simpless

    11 posts

    Hey all

    I’m now having a problem with Conditionals. I’ve read about it in the guides, but it wasn’t any help.

    I’m trying to do this:

    {if acc_type == "Student"}
        <strong>School</strong>: 
        {if st_school}
        {st_school}
        {/if}
        
        <strong>Studierichting</strong>: 
        {if st_richting}
        {st_richting}
        {/if}
        
    {/if}
    {if acc_type == "Marketeer"}
        <strong>Beroep</strong>:
        {if m_beroep}
        {m_beroep}
        {/if}
    {/if}
    {if acc_type == "Bedrijf"}
        <strong>Branche/sector:</strong>:
        {if b_branchesector}
        {b_branchesector}
        {/if}
        
    {/if}

    When I visit a page where acc_type == “Bedrijf”, it doesn’t work properly. I get “Studierichting:” as output, where it should ouput “Branche/sector:”

    I already tried using {if:elseif} but I read that Advanced conditionals are parsed differently, so that didn’t work either.

    Is my only option really to use embeds?

  • #2 / Oct 28, 2010 7:13am

    simpless

    11 posts

    I installed the Switchee plugin and my problem seems to be solved for now with following code:

    {exp:switchee variable = "{acc_type}" parse="inward"}
        {case value="Student"}
        <strong>School</strong>: 
        {if st_school}
        {st_school}
        {/if}
        
        <strong>Studierichting</strong>: 
        {if st_richting}
        {st_richting}
        {/if}
        
           {/case}
        
           {case value="Marketeer"}
                <strong>Beroep</strong>:
        {if m_beroep}
        {m_beroep}
        {/if}
            
                <strong>Werkgever</strong>:
        {if m_werkgever}
        {m_werkgever}
        {/if}
               
        {/case}
        
            {case value="Bedrijf"}
        <strong>Branche/sector:</strong>:
        {if b_branchesector}
        {b_branchesector}
        {/if}
        
            {/case}   
    {/exp:switchee}

    But still my question is, can’t I use the {if:else} and {if:elseif} without getting parsing difficulties?

    In my next example I have:

    <strong>{if acc_type == "Bedrijf"}Vestiging{/if}{if acc_type != "Bedrijf"}Woonplaats{/if}</strong>:

    This works fine, but it would be easier if I could use the {if:else} there. Would it make a difference in performance if I leave it like this or used the {if:else} instead of two {if}‘s

  • #3 / Oct 28, 2010 8:59pm

    Brandon Jones

    5500 posts

    Hi Dicoma,

    Which version and build are you using? You should indeed be able to use if:elseif there. What happens if you place that next example in a simplified template?

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

ExpressionEngine News!

#eecms, #events, #releases