ComicCMS User Manual


Template Structures :: Foreach Expanded

Guess who's making another appearance on this page. That's right: Operators.

Operators can be used on foreach loops to manipulate the items it's displaying. We're just starting to explore the functionality this gives us so for now there is only one foreach operator: reverse

The foreach example from the last page (comic_news) would list out the news posts in order, from oldest to newest. In news listing however we often want the most recent post at the top, therefore we need the most recent printed out first. Which we can do by reversing: {{foreach:comic_news:reverse}}
Now the news posts are printed out in reverse order, most recent at the top and oldest at the bottom.

Notice:Note that the operator :reverse is in the foreach block but not the endeach block. The endeach definition must not contain any foreach operators, only the variable name of the list it is related to.

ComicCMS, free php webcomic management software Copyright © 2007 Steve H