Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Between keyword after an

I'm using the between keyword to build my list of links with a | between each link:

{$ forEach x in (folder "somersetwest") $}
    {$ if nonBlank x.sidebar $}
        <a href="{$x.link$}">{$x.sidebar$}</a>
    {$ endIf $}
    {$ between $}|
{$ next $}

And I set up my template so that the article's sidebar contains the text to use for inclusion on the main menu (not all pages should have a link on the main menu).

Problem is, sometimes my sidebar is empty (on purpose), but the between instruction can't differentiate and I end up with an extra bar (or multiples).

What do you think is the easiest way to rectify?

Dan
Monday, September 01, 2003

Bit late now. I think the title should have read between keyword after a conditional.

Dan
Monday, September 01, 2003

You probably can't use the smart {between} function here. But if you move the bar up before  {$ endIf $} you will at least only have one extra bar at the end of your list.

Jorgen Brenting
Monday, September 01, 2003

I might resort to that. I was thinking about pulling a file out of the "somersetwest" folder because I can guarantee it will always be there and just hardcode the first link (obviously put the bar at the start of the line) and drop the between instruction.

Just not pretty code (-:

Dan
Monday, September 01, 2003

{$ forEach x in (folder "somersetwest") $}
    {$ if nonBlank x.sidebar $}
        <a href="{$x.link$}">{$x.sidebar$}</a>
        {$ between $}|
  {$ endIf $}
{$ next $}

isn't the above what you want?

Joel Goldstick
Monday, September 01, 2003

Yeah I tried that - but between doesn't do anything if it's not immediately before the {$next$} tag

Dan
Tuesday, September 02, 2003

I suggest having two sub folders inside "somersetwest" -- one called "linked" and one called "unlinked". Now you can change your loop to

{$ forEach x in (folder "somersetwest/linked") $}
        <a href="{$x.link$}">{$x.sidebar$}</a>
    {$ between $}|
{$ next $}

In other places where you want to list articles whether or not they are linked, you can simply use

{$ forEach x in (folder "somersetwest/*") $}

Joel Spolsky
Tuesday, September 02, 2003

I think I might have it. Thanks all.

It's very simple to leave the somersetwest folder where it is, and create a second folder (somersetfiles - whatever) at the same level.

Everything inside somersetwest can be listed in the main menu as before. Then I only need to change the sitemap to make sure that subarticles in the second folder are also looped through.

(if I create a subfolder in somerset west I need another template). Seems so straight forward now...

Dan
Wednesday, September 03, 2003

*  Recent Topics

*  Fog Creek Home