Fog Creek Software
Fog Creek Software

CityDesk 2.0-Documentation
Creating a Loop

You can create indexes and tables of contents for your site using a forEach loop in CityScript. The body of the loop will be repeated once for every article that matches a condition you specify.

Here is a simple example of a table of contents listing the headlines of all the articles in a site, with the latest articles appearing first. Each headline will be a link to the article itself:

{$ forEach x in (all) sortDescendBy .filedDate $}
<p><a href="{$x.link$}">{$x.headline$}</a></p>
{$ next $}

The syntax is:

{$ forEach n var in (condition) sort-order $}
.... loop body ....
{$ next $}

Note the parentheses around condition which are always required.

n is an optional number, greater than zero, indicating the maximum number of articles that you want included. If omitted, all articles that match condition are included in the body of the loop. For example, to list the headlines of the 10 most recent articles:

{$ forEach 10 x in (all) sortDescendBy .filedDate $}
{$ x.headline $}
{$ next $}

var is a variable name, for example, x, which should start with a letter or underscore and must consist entirely of letters, underscores, and digits.

condition is a clause which determines which articles to include. You can simply use (all), which returns all the articles in your site. To include a subset of all the articles in your site, see Determining Which Articles To Include.

sort-order is optional. It can be either sortAscendBy .field or sortDescendBy .field.

To sort in ascending order (A...Z):

{$ forEach var in (condition) sortAscendBy .field $}
.... loop body ....
{$ next $}

Note the dot in front of the attribute, which is always required. To sort in descending order (Z...A):

{$ forEach var in (condition) sortDescendBy .field $}
.... loop body ....
{$ next $}

If you do not specify a sort order at all, CityDesk will list the articles in the order in which they appear in the main window. To change the order, see Manipulating the Site Tree.

Inside the loop body, you can use

{$ var.field $}

This will extract any field from the article.

field is one of the following fields:

headline
author
fileName
body
filedDate
filedTime
modifiedDate
modifiedTime
keywords
teaser
sidebar
about
extra1
extra2
link

 

CityDesk Documentation -  Home


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