Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

turning menu options on and off

Quote Reply
turning menu options on and off
Since the beginning, I've wanted to be able to turn menu options on and off on certain pages, without having a large amount of header files laying around.

There is no really easy solution, outside of dynamically generating the header, but that is excessive, and can be intensive, depending on how complex your needs are.

The use of CategoryID and Category to turn "Home" on and off, worked only a bit. It didn't work really well on the pages like add and new.

Here's a better way to do it.

Figure out which menu options you want to turn on and off. Figure out your default state. For me, it was HOME "on", since I only wanted it off on the main page.

I created a global menu_HOME and set it to 1.

On the home.html template I put <%set menu_HOME = 0%> at the top of the home.html file. Since the globals are processed at the start of the run, the static globals are given a value when the template is loaded (sub routines are run as they are encountered it seems).

In the include_menu.html template, you surround the value in an <%if%> and if you want, an <%else%>

For example, if you set up a menu_ADD parameter, set to 1, on the add.html template, you could put

<%set menu_ADD% =0%>

and in the include_menu.html file:

Code:


<%if menu_ADD%>
<%if category_id%>
<a class="menu_links" href="<%db_cgi_url%>/add.cgi?ID=<%category_id%>">ADD A LINK</a> &#149;
<%else%>
<a class="menu_links" href="<%db_cgi_url%>/add.cgi">ADD A LINK</a> &#149;
<%endif%>
<%else%>
ADD A LINK &#149;
<%endif%>


This will put a "linked" "ADD A LINK" button on every page, with the ID parameter if necessary, but on the add.html page, it will show up as unlinked. Since you are already there... why have it linked? You could eliminate it, by removing the else clause.

This is simple, and since virtually all the "work" is done in the template parser as simple if tests, it shouldn't impose much of a penalty, no matter how complex you try to make it.

I've been implementing this on my sites the past few days, and it seems to be working pretty well. No major snags so far, at least.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.

Last edited by:

pugdog: Mar 15, 2002, 11:16 PM