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.

Conditional

November 29, 2011 7:55am

Subscribe [2]
  • #31 / Jan 19, 2012 5:05am

    {segment_2} does seem to work but just not with Matrix, this was my fault as there is a different type of field for Matrix.

    I have used the query module a few times, but I am not sure how I could use it here.

    The above example I posted, could this be used for each option? or would this bulk out the code too much?

  • #32 / Jan 19, 2012 5:12am

    Matt Powell

    42 posts

    it would bulk out the code yes, but if it works it would be worth trying. you can then try and simplify it down if you get it working as expected.

  • #33 / Jan 19, 2012 5:23am

    Okay. So would the best way to do this be to duplicate the code below for each different condition? or is there a simpler way to use all the conditions with this?

    {if segment_2 == "2012"}
    
    {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
    
    {tour_date search:option_value="2012"}
        
        <li>
        {title} - {tour_price}
     </li>
    
      {/tour_date}
    
    {/exp:channel:entries}
    
    {if:else}
    There are currently no tours that meet your criteria.
    {/if}

     

  • #34 / Jan 19, 2012 5:27am

    Matt Powell

    42 posts

    potentially yes - you may encounter problems when you are searching in ranges though.

  • #35 / Jan 19, 2012 6:19am

    Okay.

    I have started coding the conditionals for the years. (Code below)

    It works for 2012 and 2013, as they both have results. For 2014 it displays nothing, and no message.

    Do you mind checking the code to see if you can see any reasons why?

    <ul>
    
    {if segment_2 == ""}
    
     {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
      {tour_date}
          <li>
        {tour_index_preview} <!-- Snippet -->
       </li>
        {/tour_date}
     {/exp:channel:entries}
        
    {if:elseif segment_2 == "2012"}
    
     {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
      {tour_date search:option_value="2012"}
          <li>
        {tour_index_preview} <!-- Snippet -->
       </li>
        {/tour_date}
     {/exp:channel:entries}
        
    {if:elseif segment_2 == "2013"}
    
     {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
      {tour_date search:option_value="2013"}
          <li>
        {tour_index_preview} <!-- Snippet -->
       </li>
        {/tour_date}
     {/exp:channel:entries}
    
    {if:elseif segment_2 == "2014"}
    
     {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
      {tour_date search:option_value="2014"}
          <li>
        {tour_index_preview} <!-- Snippet -->
       </li>
        {/tour_date}
     {/exp:channel:entries}
        
    {if:else}
     There are currently no tours that meet your criteria.
    {/if}
    
    </ul>

    Thank you!

  • #36 / Jan 19, 2012 6:22am

    Matt Powell

    42 posts

    i think you want to include a no_results within each of your exp:channel queries rather than using the if:else - all that else is checking is if the segment if statement is not true or not, not checking against any of the results.

  • #37 / Jan 19, 2012 6:27am

    Okay. I have tried this:

    <ul>
    
    {if segment_2 == ""}
    
     {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
      {tour_date}
          <li>
        {tour_index_preview} <!-- Snippet -->
       </li>
        {/tour_date}
     {/exp:channel:entries}
        
    {/if}
    
    {if segment_2 == "2012"}
    
     {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
      {tour_date search:option_value="2012"}
          <li>
        {tour_index_preview} <!-- Snippet -->
       </li>
        {/tour_date}
        {if no_results}
         There are currently no tours that meet your criteria.
        {/if}
     {/exp:channel:entries}
    
    {/if}
    
    {if segment_2 == "2013"}
    
     {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
      {tour_date search:option_value="2013"}
          <li>
        {tour_index_preview} <!-- Snippet -->
       </li>
        {/tour_date}
        {if no_results}
         There are currently no tours that meet your criteria.
        {/if}
     {/exp:channel:entries}
    
    {/if}
    
    {if segment_2 == "2014"}
    
     {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
      {tour_date search:option_value="2014"}
          <li>
        {tour_index_preview} <!-- Snippet -->
       </li>
        {/tour_date}
        {if no_results}
         There are currently no tours that meet your criteria.
        {/if}
     {/exp:channel:entries}
        
    {/if}
    
    </ul>

    But it still doesn’t display anything if there is no results.

    Thank you!

  • #38 / Jan 19, 2012 6:40am

    Matt Powell

    42 posts

    ah yes, i see… it’s because the no_results is checking against the exp:channel:entries, which is returning all the ‘tours’ entries. so therefore it would never be empty…

    this is a bit of a stab in the dark - can you run an if against the tour_date search?

    {if tour_date search:option_value="2013"}
      {tour_date search:option_value="2013"}
        <li>
      {tour_index_preview} <!—Snippet—>
      </li>
      {/tour_date}
    {if:else}
    NO RESULTS
    {/if}

  • #39 / Jan 19, 2012 6:47am

    It returns an error:

    Parse error: syntax error, unexpected T_STRING in /home/lightand/public_html/system/expressionengine/libraries/Functions.php(656) : eval()‘d code on line 87

  • #40 / Jan 19, 2012 6:57am

    Matt Powell

    42 posts

    ok, so that if isn’t possible…

    have a look at this thread, might be of some help

    http://help.pixelandtonic.com/brandonkelly/topics/conditional_using_matrix_search

  • #41 / Jan 19, 2012 7:08am

    Thanks Matt.

    I had already found that link before you posted back. I have tested as many ways as possible.

    If I place it where you suggested it shows errors, but if I place it like below it displays a message for each list item… again!

    {if segment_2 == "2014"}
    
     {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
            {tour_date search:option_value="2014"}
          <li>
        {tour_index_preview} <!-- Snippet -->
       </li>
        {/tour_date}
     {if "{tour_date search:option_value="2014"}" == 0}
         There are currently no tours that meet your criteria.
        {/if}
     {/exp:channel:entries}
        
    {/if}

    Any ideas?

     

     

  • #42 / Jan 19, 2012 7:14am

    Matt Powell

    42 posts

    the link shows the check going like this

    {if "{image_matrix:total_rows search:section="{embed:section}”}” == 0}

    whereas yours says

    {if "{tour_date search:option_value="2014"}” == 0}

    what if you change it to

    {if "{tour_date:total_rows search:option_value="2014"}” == 0}

    —your stuff—

    {if:else}

    —your no results thing—

    {/if}

    also, note the use of the embed on that article. you could use that to save yourself a lot of code. do you know how? happy to help if not.

  • #43 / Jan 19, 2012 7:18am

    I have tried this:

    {if segment_2 == "2014"}
    
     {exp:channel:entries channel="tours" limit="10" orderby="date" sort="asc" dynamic="no"}
            {tour_date search:option_value="2014"}
          <li>
        {tour_index_preview} <!-- Snippet -->
       </li>
        {/tour_date}
     {if "{tour_date:total_rows search:option_value="2014"}" == 0}
         There are currently no tours that meet your criteria.
        {/if}
     {/exp:channel:entries}
        
    {/if}

    but it still displays a message for each list item, currently 3…

    Wow, thank you. I have no idea how to do the embed thing, that’s very kind of you.

    Thank you 😊

     

  • #44 / Jan 19, 2012 7:28am

    Matt Powell

    42 posts

    are you able to get this up onto some webspace somewhere? i’d like to help but really need to be able to troubleshoot directly…

    i’ll set up the embed too to show you how.

  • #45 / Jan 20, 2012 5:42pm

    Dan Decker

    7338 posts

    Wow, Matt has really stepped in and done a wonderful job helping you get this sorted out.

    You guys have taken this to the next level and have a great discussion going. As such, I’ll move this into Community Help to keep the thread alive.

    It’s so wonderful to see the community rocking it out!

    Cheers!

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

ExpressionEngine News!

#eecms, #events, #releases