Welcome to WebmasterWorld Guest from 126.96.36.199
Forum Moderators: phranque
All of that seems rather simple. However, I have a big problem: Say my website is about shoes. I have three categories in the top navigation: Sports shoes, Cool Shoes, Women's shoes. If the user is on the page about "sports shoes", I want that part in the top navigation to be highlighted, if he's on the page about "cool shoes" that part in the top navigation should be highlighted, etc..
In order to get that done (if it was only 3 pages), I would normally create three different pages and the navigation code (the html) would look a bit like this:
<li class="selected"><a>sports shoes</a></li>
for the "cool shoes"-page like this:
<li class="selected"><a>cool shoes</a></li>
and for the women's shoes page..well you can imagine. However, if I want to do that I have to create a separate file for each one...which Im trying to avoid by using SSI (not a problem with 3 navigation buttons, but if you have a top navigation with 10 and a sub-navigation with some more..Id prefer to avoid this).
Is there any possibility to get this done with mostly HTML and CSS knowledge (I'm trying to make some progress with the site and if I have to learn java script for another dozens of hours or more I'd probably forget about the highlighting effect for now). I'd be willing to look up a few things to get this done, but it's probably not worth having to learn another programming language for me right now.
Is there the possibility to use some code like this in the separate file (which contains the html code for the navigation):
<li class="selected1"><a>sports shoes</a></li>
<li class="selected2"><a>cool shoes</a></li>
<li class="selected3"><a>women's shoes</a></li>
and then use a little bit of dynamic code on each page (right before I use SSI to call(exp?) the navigation) so the browser understands which part of the navigation has to be highlighted?
If something like that is possible (I understand that the above is probably not possible, but hopefully you understand my train of thought?:)) without learning a lot of java script or something (I'm willing to spend a bit of time - say 5 hours max. ;)), but if it takes longer than that, I should probbaly postpone it for now (for now my main goal is launching the site).
THANKS A LOT! I really appreciate your help...If such a forum had existed back when I was programming computer games in elementary, I mgiht have never stopped it ;)
<!--#include virtual="/my-menu.cgi" -->
. . . and output the links based on the referrer. But that's probably just a comfort zone on my part. :-)
The right way to do it would probably be to use the limited but powerful functions available to SSI. I have not tested the below, but it should be a fun project.
First, you include another server side include:
<!--#include virtual="/ssi/menu-parser.shtml" -->
Then in menu-parser.shtml, you do a bit of trickery.
SSI has access to the same environment variables as any server-side program. One of those is DOCUMENT_URI, the URI to the document. You could combine that with the if construct and expr function in SSI to do this:
<!--#if expr='"$DOCUMENT_URI" = "/file1.shtml"' -->
<a href="file1.shtml" class="highlight-class">File 1</a>
<a href="file1.shtml">File 1</a>
<!--#if expr='"$DOCUMENT_URI" = "/file2.shtml"' -->
<a href="file2.shtml" class="highlight-class">File 2</a>
<a href="file2.shtml">File 2</a>
If the first matches, it displays the version with the class, otherwise, it displays the regular link.
Haven't tested it but it should work, you may have to run a script or two to see if the document URI is a full path or relative.
Most folks use a hybrid of CSS and an id or class on the body element to change the style on the page which causes HTML and CSS bloat when the server can handle the update on the fly quite nicely without having to update code every time you add/remove pages from your site.
Basically what you end up doing is using the same navigation for everything, it remains "static", so-to-speak. You buffer the navigation by storing it in a string variable for manipulation by your server-side processing. The server compares any links found in the string with the current link being requested and applies your changes on-the-fly.
[edited by: encyclo at 11:48 pm (utc) on Oct. 13, 2008]
[edit reason] moved from another location [/edit]
You can have your SSI call a program, rather than a static file. Then your program returns the html relevant for the page it's delivering to. For example, your SSI call could be:
Then your Perl program looks at what page is calling the script, and returns the HTML appropriate for that page.
Anyway thanks for your efforts!
Anyway thanks for your efforts!