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.

Limiting an IF statement

July 30, 2010 2:32pm

Subscribe [6]
  • #1 / Jul 30, 2010 2:32pm

    webster10

    9 posts

    I am having trouble figuring how to limit an if statement.

    {if a == "BLAH" && b == "BLAH BLAH"}Hello!{/if}

    I end up getting multiple returns.  All I want is a single return.  A limit of 1 that indicates that “yes, this if statement is true or exists”

    Any help will be greatly appreciated.

  • #2 / Jul 30, 2010 3:09pm

    Ingmar

    29245 posts

    What version and build are you on? Can you give us a less abstract example or piece of code? Perhaps a link?

  • #3 / Jul 30, 2010 3:56pm

    webster10

    9 posts

    That is as clear as I can be.  How do you limit the returns with an “if” statement.

  • #4 / Jul 30, 2010 4:02pm

    Ingmar

    29245 posts

    Technically & syntactically there’s nothing wrong with your statement. If you tell us a little more about what it is you’re trying to achieve we might be able to help you further.

  • #5 / Jul 30, 2010 4:16pm

    webster10

    9 posts

    When I write it that way, the “if ” statement repeats as many times as that statement is true.  I want it to only display once.

  • #6 / Jul 30, 2010 4:23pm

    Ingmar

    29245 posts

    You can probably use something like

    {if count == 1}

    ... but that would require to be within an exp:weblog:entries loop. Again, perhaps you could show us a little more code?

  • #7 / Jul 30, 2010 5:56pm

    webster10

    9 posts

    I am trying to keep the “If ” statement from looping.

    {exp:weblog:entries weblog="guitars"}
    
    {if dealer-select == "Wildwood" && bodyShape == "Stratocaster®"}
    <h2>STRATOCASTER</h2><p><span>®</span><br />
    {/if}</p>
    
    <p><br />
    {/exp:weblog:entries}

    This loops and prints STRATOCASTER for every stratocaster in the database.  I want it to only print it once if the “if” statement is true.

  • #8 / Jul 31, 2010 2:43pm

    Greg Salt

    3988 posts

    Hi webster10,

    The conditionals on their own will not do this, they are doing exactly what you have told them to do. Are you using categories to organise your data? If so you might use the weblog:category_heading tag combined with perhaps an embed. This is going to depend on how you have structured your data and your template layout though. I recommend posting in the CodeShare Corner forum to get some community input into what you’re trying to do. I can move this thread for you if you wish.

    Cheers

    Greg

  • #9 / Jul 31, 2010 7:36pm

    What about something like this?

    {exp:weblog:entries weblog="guitars"}
    {if dealer-select == "Wildwood" && bodyShape == "Stratocaster "}
    {if count == 1}
    <h2>STRATOCASTER</h2><p><span>®</span><br />
    {/if}<br />
    {/if}</p>
    
    <p><br />
    {/exp:weblog:entries}

  • #10 / Aug 01, 2010 4:35pm

    Greg Salt

    3988 posts

    Hi webster10,

    How are you getting on? Dylan’s suggestion will work if all your entries match the first conditional. Have you got a URL where you could show us the type of output this entries tag will produce by default?

    Cheers

    Greg

    @Dylan, thanks for helping out.

  • #11 / Aug 02, 2010 2:26pm

    webster10

    9 posts

    How do I keep the “If Statement” from looping?  This example works but it loops in the amount of times this statement is true.

  • #12 / Aug 02, 2010 5:24pm

    Ingmar

    29245 posts

    I am afraid that’s just the nature of conditionals. There is no way to keep them from looping, they will match every time they are true.

    To be frank with you, I think you really might be better off using categories.

  • #13 / Nov 01, 2010 8:47am

    Sue Crocker

    26054 posts

    Closing older thread..

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

ExpressionEngine News!

#eecms, #events, #releases