Subject: Re: How to? Tue Jan 05 21:36:38 1999 > On each page of the site will be a fairly lengthy text-based navigation > column running down the left. gad.. text/link-based navigation. on behalf of web-luddites everywhere, let me be the first to say we love you. ;-) > It will be exactly the same on each page, *except* that I want to > highlight the currently-selected page/section -- probably by the usual > convention of removing the href tag from it so it's not a link: > > [...] > > So what do people think is the best route to go here? Basically, I want > the SSI to execute conditionally: "check the URL of the page that is > being loaded; examine the include file that renders the navigation > column; when a URL in the include file matches the URL that is being > loaded, strip out the tag from that text." Apache allows you to set an environment variable with an SSI. that variable will be visible to any script you call thereafter. you can use globals more or less the same way you use hidden variables in regular forms. the back-end mechanism is different, but the principle is the same. it's an invisible selector which allows you to switch the behavior of the script automagically. the solution to the problem you've described would be a script that uses a simple database. define a key, a default value, and a highlighted value for each item in the navbar. then use an SSI to define a unique key for each page in the site. when you call the script, it can examine the key to decide which item will need special formatting. here's a simple example, using dewey notation for the keys and a tab-delimited text file as the database. to call it, use the following sequence in each of your webpages: with appropriate values for x and y. ---- mk_navbar.pl ---- #!/usr/local/bin/perl $DEFAULT = qq(
## TEXT ##); $HIGHLIGHT = qq(
## TEXT ##); while ($line = ) { next unless ($line =~ /\S/); chop $line; ($key, $txt, $url) = split (/\t+/, $line, 3); $text{ $key } = $txt; $href{ $key } = $url; $n = substr ($key, 0, 1); $topics{ $n } = 1; } @keys = keys %text; for $n (sort keys %topics) { @list = grep (/$n.\d/, @keys); for $item (sort @list) { $tmpl = ($ENV{'PAGE_ID'} eq $item) ? $HIGHLIGHT : $DEFAULT; $tmpl =~ s/## HREF ##/$href{ $item }/; $tmpl =~ s/## TEXT ##/$text{ $item }/; print "$tmpl\n"; } print "
\n"; } __END__ 1.0 TOPIC ONE t1/index.html 1.1 item 1 t1/p1.html 1.2 item 2 t1/p2.html 1.3 item 3 t1/p3.html 2.0 TOPIC TWO t2/index.html 2.1 item 1 t2/p1.html 2.2 item 2 t2/p2.html 2.3 item 3 t2/p3.html 3.0 TOPIC THREE t3/index.html 3.1 item 1 t3/p1.html 3.2 item 2 t3/p2.html 3.3 item 3 t3/p3.html ---- EOF ---- the actual output structure you've described: > __Publications__ > __Working Papers__ > __Backgrounders__ > Speeches << not a link > __Journal Articles__ would take a bit more work to generate, because it looks like you're using nested lists. that would involve some additional fiddling around with the ways pieces are formatted and organized, but the principle would be the same. i can bid that off-list for you, if you'd like. (yes, i'm schmoozing.. you've just gone corporate, and i've just gone back to freelancing. parity has been maintained, but i've gotta start hitting the bricks again ;-)