Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Where am I? Navigation

Just happened upon this stuff and it looks interesting :-)

Question: Can IF be used to compare values?

What I'm really wanting is to highlight the current article in the navigation list.

{$foreach x in (folder "articles")$}

IF (x.isTheActivePage)
You are HERE ---> {$x.headline$}
ELSE
{$x.headline$} -- {$x.link$}
ENDIF

{$next$}

Tim Colson
Tuesday, May 14, 2002

This is a much requested but, so far, unavailable feature.

tk
Tuesday, May 14, 2002

I have solved this using foreach and javascript. For the javascript I've created an empty template with the .js extension.

// ***********begin javascript article********
var arMenu=new Array (
{$foreach a in (and (filename "index") (folder "")) $}
  "/{$a.abslink$}","Home",{$next$}
{$foreach a in (and (filename "index") (not (folder ""))) $}
  "/{$a.abslink$}","{$a.headline$}",{$next$}
  "/{$.abslink$}","{$.headline$}");
// arMenu[][2] contains all paths\index.html with known header names

var pijl=' <IMG src="/mnu/pijl.gif"> ';
var topMenu="";
function FindMenu(path)
{
  path=unescape(path);
  path=path.replace(/\\/gi,"/"); 
  for (var index=0;index<arMenu.length;index+=2)
  {
    cmp= arMenu[index].substring(0,arMenu[index].lastIndexOf("/"));
    if (path == cmp)

    {
      if (topMenu != "") topMenu=topMenu+pijl;
      topMenu=topMenu + '<A href="'+arMenu[index]+'">'+arMenu[index+1]+"</A>";
      return 1;
    }
  }
  if ((path==arMenu[arMenu.length-2]) && (path.indexOf("index.")<0) )
  {
      topMenu=topMenu + pijl + '<A href="'+ arMenu[arMenu.length-2]+'">'+arMenu[arMenu.length-1]+"</A>";
      return 1;
  }
  return 0;
}

// find this file
    var menu="";
    var myString=unescape(location.pathname);
    myString=myString.replace(/\\/gi,"/");  //make it work for previews

    var lastindex=0;
    var index = 0;
    var einde=0;
    var startindex=lastindex+1;
    do {
      index = myString.indexOf("/", lastindex);   
      if (index<0) FindMenu(myString.substring(startindex-1,1000));
      else
        if (!FindMenu(myString.substring(startindex-1, index)))
        {
          startindex=index+1;
        }
      lastindex=index+1;
    } while (index != -1);

// ***********end javascript article********


Using
<script>document.write(topMenu)</script>
in the template

I write a menu like
_home _product _page
(where _x is a hyperlink to a page 'x')

The IMG tag is a '>' symbol; unfortunately I can't use the FOG reference in here since Citydesk always generates relative links which will not work since the menu is used at different locations than the location of the script.

The script assumes that there is an index article in each folder.

I hope this helps you.

Adriaan van den Brand
Wednesday, May 15, 2002

I've posted it at tk's website as a cty-file
http://tk-jk.net/city/Articles/fog0000000010.html

Adriaan van den Brand
Monday, May 27, 2002

*  Recent Topics

*  Fog Creek Home