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.

controlling loops using EE tags

August 21, 2007 1:52pm

Subscribe [2]
  • #1 / Aug 21, 2007 1:52pm

    Rob Lyons

    34 posts

    setting flags using EE tags

    I’m often confronted with a situation where I’d like to loop through a set of entries and change what happens once a certain condition has been met. Hence, I’d like to set a variable with an initial state, then when a certain kind of entry comes along change the variable so that a different set of instructions is followed from then on.

    For example, for a forthcoming conference, I have sessions over two days. I’d like to start the list with the word ‘Saturday’ then loop through the entries until the entries for the next day are reached, then display ‘Sunday’ followed by those entries. However, I just want to display the day once, so I would like to create a variable called ‘day_displayed’ or somesuch and set it to ‘yes’ once the first entry for that day has been displayed.

    Here’s the page, to illustrate the point:

    http://www.battleofideas.org.uk/index.php/site/overview/

    After the session “All tested out”, it should display “Sunday”.

    Is there a way in EE of creating a variable, setting a value, then testing the value with each loop through the {exp:weblog:entries} tag, altering as required? Or should I just code it all in PHP, which wouldn’t be a huge job, but I’d prefer to do it EE tags alone if possible.

    A quick point: if I stick PHP inside global conditional tags, it doesn’t seem to work eg:

    {if condition==true}
      <?php [some code] ?>
    {/if}

    Is that because the parsing order makes it impossible?

    I’m running version 1.6.0

    Rob

  • #2 / Aug 21, 2007 2:25pm

    Ingmar

    29245 posts

    For example, for a forthcoming conference, I have sessions over two days. I’d like to start the list with the word ‘Saturday’ then loop through the entries until the entries for the next day are reached, then display ‘Sunday’ followed by those entries. However, I just want to display the day once, so I would like to create a variable called ‘day_displayed’ or somesuch and set it to ‘yes’ once the first entry for that day has been displayed.

    Look into {date_heading} for a native solution to this problem.

    {exp:weblog:entries}
    {date_heading display="daily"}{entry_date format="%l"}{/date_heading}
    {/exp:weblog:entries}

    Otherwise, yes, I’d use pure PHP.

  • #3 / Aug 21, 2007 3:13pm

    Rob Lyons

    34 posts

    I’m assuming this only works with the entry_date field? It would be great if the {date_heading} part worked with the custom date field.

  • #4 / Aug 21, 2007 3:58pm

    Ingmar

    29245 posts

    It does. All that {date_heading} does is to display some information in a given interval, ie once every day, every wekk, month etc.

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

ExpressionEngine News!

#eecms, #events, #releases