Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Nested looping

I seem to recall some information on writing nested loops.  I want to create a menu with articles (no problem), and then create submenus for each major topic by including them in a subfolder that has the name F + "MainTopicFile"

I've tried some foreach nestings but I get errors.

Any ideas?

Joel C. Goldstick
Saturday, October 05, 2002

can you copy the code you've tried in here?

Adriaan van den Brand
Saturday, October 05, 2002

Using Articles folder with several articles, one called "Autism"

One subfolder called "FAutism" with 2 articles in it

In the Autism article I put FAutism in extra2



Here is some code I tried.

{$ foreach x in (folder "Articles") $}
            <a id="{$ x.filename $}" href="{$ x.link $}">
        {$ x.filename $}{$ if nonblank x.extra2 $}\{$ x.extra2 $}</a>

            {$ foreach y in (folder "{$ x.filename $}\{$ x.extra2 $}" $}
                <A id="{$ y.filename $}" href="{$ y.link $}">{$ y.headline $}</a>
            {$ next $}
                


        {$ next $}
    {$ endif $}

Joel C. Goldstick
Saturday, October 05, 2002

Disregard my previous post.  It is a mess.  Here is better code, but it doesn't work:

{$ foreach x in (folder "Articles") $}
    <a id="{$ x.filename $}" href="{$ x.link $}">
        {$ x.filename $}
    </a>
    {$ if nonblank x.extra2 $}
        {$ foreach y in (folder "{$ x.filename $}\{$ x.extra2 $}" $}
            <A id="{$ y.filename $}" href="{$ y.link $}">{$ y.headline $}</a>
        {$ next $}
    {$ endif $}
{$ next $}


The publishing error message box shows:
ForEach: folder "{$ x.filename $}\{$ x.extra2 $}" not found (\Articles\Autism:3098)
ForEach: folder "{$ x.filename $}\{$ x.extra2 $}" not found (\Articles\FAutism\New Article 2:3098)
ForEach: folder "{$ x.filename $}\{$ x.extra2 $}" not found (\Articles\FAutism\New Article:3098)

Joel C. Goldstick
Saturday, October 05, 2002

Unfortunately this is one of those things you can't do.

Joel Spolsky
Saturday, October 05, 2002

I think this is a similar limitation I've encountered.

($foreach x in (all) $}
{$.doSomeMagicWithX$}
{$next$}

doesn't work either.

It is also not possible to define the foreach in a variable . A variable only works if it contains complete foreach loops.

Adriaan van den Brand
Sunday, October 06, 2002

*  Recent Topics

*  Fog Creek Home