Fog Creek Software
Fog Creek Software

CityDesk 2.0-Documentation
Before and After in Loops

The optional {$ before $} and {$ after $} sections of a forEach loop are used to provide text which appears, um, before and after the other items. This may sound unnecessary, after all, you can always put text before and after the entire forEach loop, right?

Well, before and after have one advantage: the text will only appear if the loop has at least one value. This is very useful for those times when you want to avoid introducing a list that has no elements (see Alternate Text for Empty Loops for an example). It is also useful to create syntactically correct HTML text so that, for example, you never create a <table> without any <tr> rows or a <ul> list without any <li> list items.

Here's an example in HTML with a bullet list:

{$ forEach x in (all) $}
    <li>{$ x.headline $}</li>
{$ before $}
    <ul>
{$ after $}
    </ul>
{$ next $}

By using before and after in this way, the opening <ul> tag and the closing </ul> tag will not appear unless there is at least one item in the list. By combining before and after with the else section, you can create a completely different appearance when there are no artricles matching the condition in the forEach statement.

CityDesk Documentation -  Home


©Copyright 2001-2003 Fog Creek Software, Inc. All Rights Reserved.