Fog Creek Software
Discussion Board

Knowledge Base
Terry's Tips
Darren's Tips

create hierarchical menu

I would like to create an hierarchical menu with cityscript.
Suppose you have 4 folders :


Each folder has an index file looking like this :

{$ foreach x in (and (thisFolder) (not (thisArticle))) $}

This will list the all headlines of the articles in the folder.

Now you need a way to loop through all index files, and write the body of it ( which is the script mentioned above ).

Except looping through all index files and then write the body, which also contains an foreach loop does not work because a nested foreach loop is not permitted.

How is this properly done in cityscript?
Or is there no generic way to do this...

jan kieftenbeld
Wednesday, November 17, 2004

I do something like this. I have a menu in with 6 categories (folders) each having several links (articles in the folder). In each folder I use "title" articles which I identify by placing something in "About" and "Extra1. "Subtitle" articles have something in "About" and nothing in "Extra1."

So, I use "if blank" to sort out titles articles from content articles. As in your case, I'm writing more scripts than perhaps I'd like. This is the general script I use (with some variation) on the 14 different menus I use on the site.

<!-- Home page left menu start  -->
<table cellspacing="0" cellpadding="0" width="160" border="0">
{$ forEach x in (folder "HomePageDocs/*")$}
{$ if blank x.About $}
<!-- Blank "about" are articles -->
<td><div class="menuitem"><a class="toplink" href="{$x.sidebar$}"><b>{$x.headline$}</b></a></div></td></tr>
{$ endIf $}
{$ if nonblank x.about $}
<!-- non-Blank "about" are titles -->
{$ if blank x.Extra1 $}
<!-- Blank "Extra1" are subtitles -->
<tr><td><div class="menusubtitle">{$x.headline$}</div></td></tr>
{$ endIf $}
{$ if nonblank x.extra1 $}
<!-- non-Blank "about" are Main titles -->
<tr><td><div class="menutitle">{$x.headline$}</div></td></tr>
{$ endIf $}
{$ endIf $}
<!--Home page left menu end-->

Wednesday, November 17, 2004

*  Recent Topics

*  Fog Creek Home