Fog Creek Software
Discussion Board

Knowledge Base
Terry's Tips
Darren's Tips

looping on folders?  is it possible?

I would like generate a navigation bar based upon the the folders within my site.  I have figured out how to loop on the contents of a folder but not how to loop on the list of folders themselves.  Without the folder loop, every time I add a folder I have to edit this script.  What can I say, I'm lazy :-)

BTW, if you have an answer to this, is there any way to make the script run from within the context of the current folder?  Similar to using the /s command in the MS-DOS Dir command.

kevin sherwood
Sunday, December 30, 2001

There is a way to accomplish what I think you want.  If in each folder you add an article that has the name of the folder and a keyword "menu"

You can then generate your folder-based menu with the condition (keyword_contains "menu").  There are other neat things you can do with your new menu article.

Of course the scripts that operate on your articles may need to use the condition not(keyword_contains "menu")

Sunday, December 30, 2001

This makes sense but does not solve the problem I am asking about.  Maybe an example will help.

I want a navigation bar to display on my web site that looks like this. 

Folder A
- Article 1
- Article 2
Folder B
- Article 3
- Article 4
Folder N
- Article Z-1
- Article Z

Substititute meaningful names for Folder and Article and lose the alphabet and numbers.  The articles would be active links to the actual article and the Folder could link to the index.html in the folder.

kevin sherwood
Monday, December 31, 2001

Oh, I see.  I still think you can make it work:

Do a "foreach x in all" or whatever selects the folders you need for your menu.

In Folder A, name an article, "Folder A" with the actual articles named, " - Article 1"  " - Article 2" - the article names formatted as you want to see them in the menu.

You could use the sidebar, teaser or whatever to be the name that shows up in your menu.  You still might need a keyword like "foldername" so you could exclude the folder-name article when you need to.

Now you are stuck with, "where does the menu's link to 'Folder A' go."  You might have a page "Folder A" which contains a script that lists all of the articles in "Folder A"

I do something like this for the "Recent meeting minutes" menu on this page:

I'm sure there are more clever ways than this to make it work.

Monday, December 31, 2001

I'm trying to figure out why this doesn't work. Create an article that has an index for a particular folder as the body, and the name of the folder as the extra1 field.

{$foreach x in keyword_contains "index"$}

<a href="{$$}">{$x.headline$}</a>
{$foreach y in folder "{$x.extra1$}"$}
<a href="{$$}">{$y.headline$}</a>
test: {$x.extra1$}

if it outputs:

<a href="fog0000000012.html">music</a>

test: music

and clicking on the "music" link brings me to a page _with_ articles in it, why doesn't the "y" loop process? I don't think it's nested too deep. Maybe I'm not taking into account variables?

why doesn't the y loop run?

Mark W
Friday, February 01, 2002

*  Recent Topics

*  Fog Creek Home