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.

Switch tag within if statement always firing

May 16, 2013 6:27pm

Subscribe [2]
  • #1 / May 16, 2013 6:27pm

    xynergy_inc

    10 posts

    Hey,

    So I’m having a trouble here with a switch statement. First of all, my goal (in case there’s an easier way that avoids all this) is to filter entries by a Date field. As the “search” parameter can’t do comparisons, instead I used some input php and an “if” statement to filter through them and only display the ones that fall within the date range.

    {if listing_dob < <?php echo $min_dob; ?> AND listing_dob > <?php echo $max_dob; ?>}
     <a href="http://{permalink=%27adoption_listings/index%27}" class="listing_thumb">_  {listing_image:thumbnail}_  <span class="listing_thumb_name">{listing_first_name}</span>_        </a>
     {switch='||</div><div class="row-fluid">'}
          
    
    {/if}
     {if count == total_results}
      </div>
     {/if}

    Which works fine except that the switch statement seems to always fire, not just when the if statement is satisfied. Any ideas as to why this is?

  • #2 / May 17, 2013 12:35pm

    travisb

    172 posts

    The switch is going off of the exp:channel:entries loop number, and will not “pause” if inside a conditional, so that may not work for you even if it did obey the conditional.

    How about using Stash (devotee, github)? You could do something like:

    First set your Stash list (outside of any entries loops):
    
    Stash: set_list
     Entries loop: run your channel entries loop
      If conditional: your current if conditional
       set your content 
       for example:
       {stash:item_listing_thumb_name}{listing_thumb_name}{/stash:item_listing_thumb_name}
      /If
     /entries
    /set_list
    
    Then output your Stash list, which only consists of entries that met your conditional:
    
    Stash: get_list
     output your stash list content
     for example: <span class="{item_listing_thumb_name}">.....
     
     use Stash switch here where needed (ie:  {switch='||</div><div class="row-fluid">'} )
    /get_list
    </div>
     
    Note: not sure, but your get_list may have to be in an embed because of parse order. If it doesn't work, try the embed.
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases