Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Recursive Table of Contents Generation

Hello!

I have a hierarchy of section folders and articles that might change over time and I want to be able to automatically generate a table of contents for it, listing each section and article names. The folder names can't be hardcoded, because the end user might change them or add new ones.

I have tried creating a folder for each section, then in each folder I have a special article I called "list", that contains the name of the section in its "headline" field. In its "body" I have a loop that grabs the titles of all the articles in the current folder using the (thisFolder) condition.

Then, in the root folder, I have my "Table of Contents" article that is simply a loop that prints the "headline" and "body" fields of my special "list" articles.

Unfortunately, this doesn't work, because the Table of Contents loop, that uses the (filename "list") condition for all folders, is processing the (thisFolder) loop in the "list" articles in the context of the root folder and not in the context of each section folder as I expected it would.

This way, all I get is a the list of articles in the root folder.

Has anybody done this before with CityDesk and tell me how to do it? Or maybe tell me what is wrong with what I have?

Thank you.

Thompson Marzagao
Friday, January 02, 2004

This is the way I do it, too. You have to change the "list" article in each folder to include the folder name itself in the foreach condition. That means each "list" article is a tiny bit different. It's a nuisance, I know, but there's no known workaround.

Joel Spolsky
Tuesday, January 06, 2004

I'm using this exact thing to create a multi-tier javascript menu system.

The folders are the tiers and if an Article has an extra2 field then that is the menu name (and its included in the menu). If there is no extra2 field then its not put in the menu.

Can you guys post the CS for what you're talking about? Will likely help me a lot.

cheers
Paul

Paul Tyma
Tuesday, January 06, 2004

Well, since I have a set of articles organized in different sub-folders, I figured I couldn't do the table of contents simply with CityScript.

Also, the folder names can change over time, so I couldn't do any harcoding and I didn't want to bother my client with custom extra fields.

So, I ended up building an ASP based solution (I would have used PHP or Perl, but the my client's server doesn't have them):

I created a simple CityScript loop to list all the articles within the folder "Content" and its sub-folders:

{$ forEach item in (folder "Content/*") $}{$ item.absLink $}||{$ item.headline $}
{$ next $}

This generates a list of all articles' absolute links and headlines delimited by two pipe characters.

Then I use my ASP script to parse the generated list and build my table of contents. The generation of the table of contents is now completely automated (at least for one level of sub-folders, but that's all I need).

I guess using server-side scripting with CityDesk is not so bad after all. :) Only breaks the local preview.

Thanks for your help.

Thompson Marzagao
Tuesday, January 06, 2004

*  Recent Topics

*  Fog Creek Home