Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

building subnav lists for variable folders

I am trying to develop a single template that will create a subnav list of articles (a left nav)  of all articles in the "current" folder.

This would be a "same level" list of links.

I can easily create list loops that do what I need, but only when I "name" the folder, or the "keywords." I'd really like to see if I can use CityScript to pull this one off... without my having to create a template for each folder/category.

Any ideas out there?

Thanks, Mike C.

Michael Costantino
Tuesday, November 26, 2002

The short answer is we can't do it yet but there is some hope.

http://discuss.fogcreek.com/CityDesk/default.asp?cmd=show&ixPost=3051&ixReplies=4

http://discuss.fogcreek.com/CityDesk/default.asp?cmd=show&ixPost=1588&ixReplies=3

tk
Tuesday, November 26, 2002

My current "workaround" is that I'm doing this with a variable as follows:

{$ foreach x in (and(folder "cycling") not (filename "Index")) SortDescendBy .fileddate $}

So whenever I create a new article in the "cycling" folder I just add the {$.SideCycling$} reference in the Sidebar field. This give me the index listing you want, without creating a separate template.

The only other "minor" disadvantage is that it includes the current article in the index.

Scott McDonald
Thursday, November 28, 2002

Scott, could you change your variable to something like:

{$ foreach x in (
and((folder "cycling")(not(filename "Index"))(not(filename "{$.filename$}")))) SortDescendBy .fileddate $}

That would drop the current file from the list.

I can't remember whether you can reference variables within the conditions or not. Shame if you can't, I see a feature request coming on if so!

Ian Jones
Thursday, November 28, 2002

Great idea, Ian, but as far as I know the filename condition requires an explicit reference. In other words, you can't refer to the ID of the current article as you're suggesting.

It's true, I could dump the variable code into the sidebar field and "hardcode" the filename as I create the article, but I think this is somewhat defeating the purpose of the variable in the first place.

Scott McDonald
Thursday, November 28, 2002

Ah well, maybe this will be addressed in a future version of CD. The inability to reference the current article or it's folder path or sub folders without hard-coding is probably the biggest limitation at the moment.

Ian Jones
Friday, November 29, 2002

Scott,
The variable trickery works nicely, thanks.

Listing the current page is not too bad, but I'm thinking there may be a neat JavaScript-based style change that could show which listing is the current page... after all, we can get CD to "name" each anchor tag. I'll post it if I get it worked out.

Michael Costantino
Sunday, December 01, 2002

Seeing Scott's suggestion I realize you can go further - at least in my case. I have navigation links at the left which are a simple foreach on a keyword. I can have a subnavigation menu popping up when wanted:
1. create navigation variables per folder
2. put the variable in a field like sidebar (or another field)
3. add $.sidebar$ to the foreach that creates the left menu

That way, the extra relevant submenu will be shown when we want it, i.e. when we put the proper navigation variable in the chosen article field.

Paul Iliano
Friday, December 06, 2002

Continuing on with Scott's tactic... here are code frags for my stylesheet variable, and a single one of my subnav variables.

The process: 1) paste the appropriate subnav variable in the extra1 field for each article; 2) name each page with underscores between the words so that CSS doesn't flip out.

The end result: the list of subnav links shows the current page in bold/black/nounderline. A pretty workable statement of "here I am."

=====
stylesheet fragment
=====
a:link {
    color: #000066;
}
a:hover {
    color: #000066;
    text-decoration: underline;
}
a:visited {
    color: #000066;
}
a:link.{$.filename$} {
    color: #000000;
    font-weight: bold;
    text-decoration: none;
}
a:hover.{$.filename$} {
    color: #000000;
    font-weight: bold;
    text-decoration: none;
}
a:visited.{$.filename$} {
    color: #000000;
    font-weight: bold;
    text-decoration: none;
}

=====
subnav variable
=====
{$ foreach x in (and(folder "about_us") not (keyword_contains "index")) $}
<p style="margin-top: 6; margin-bottom: 6"><a class="{$x.filename$}" href="{$x.link$}">{$ x.headline $}</a></p>
{$ next $}


CD and CSS work pretty well together.

Michael Costantino
Friday, December 06, 2002

*  Recent Topics

*  Fog Creek Home