Scroll To Top

Enter a query to search our site. Note that you can use "*" and "?" as wildcards. Enclosing more than one word in double quotes ("CSS Layout") will search for the exact phrase.

PVII Knowledge Base

1. Select a product ...
2. Select category ...
3. Search the Knowledge Base...

Question #148

I have a lot of pages that do not appear as part of the TreeMenu Magic (TMM) system, is there a way to automatically have a certain menu section opened based on the folder name where that page is stored?

The Answer

Prepared Jun. 2004 by Gerry Jacobsen, PVII

Note: This functionality is included and fully automated in the more recent Tree Menu Magic 2 system, which contains a complete Advanced Current Marking interface.

The TreeMenu Magic system automatically opens the menu to the pertinent section when the page loads, but this functionality requires that the page being loaded is represented as an actual link in the menu. When loading pages that do not appear in the menu you can use our special TMM Url Tweak or our TMM Text Link Tweak, however, they both require that you manually set the function arguments on each of theses types of pages.

Here's an add-on tweak that will automatically detect the folder that the page resides in and set the appropriate menu section, and all of its parents, to the open state. It will also automatically set the current page marker (the "p7currentmark" class) if the matched link is a normal (not a menu section trigger) text link. If the matched link is a menu section trigger the system will use the normal "p7minusmark" and "p7plusmark" classes and apply them appropriately. This technique simply requires that you are using a folder hierarchy for your site's pages.

The tweak works by allowing you to describe folder name/text link pairs. When the page loads the script will compare the url of the page to the folder name/text link pairs and if it finds a match the script will open the menu to the link whose link text matches the text link value in the folder name/text link pair. This will work on both normal links in the menu and menu section triggers, the match is based purely on the text value of the link.

Here's how to apply the tweak:

1. Add this new JavaScript function, P7_TMfolder(), to your script file:

function P7_TMfolder(){ //v1.0 by PVII-www.projectseven.com
 //describe the folder name, link text pairs
 var bb=new Array('folder1','text1','folder2','text2','folder3','text3','folder4','text4');
 var i,x,d,jj,hr,a,ha,m=false;
 if(document.getElementById){d=document.getElementById('p7TMnav');
 hr=window.location.href;if(d){for(x=0;x<bb.length;x+=2){
 jj="/"+bb[x]+"/";if(hr.indexOf(jj)>-1){m=true;break;}}
 if(m){ha=d.getElementsByTagName("A");if(ha&&ha.length){
 for(i=0;i<ha.length;i++){if(ha[i].firstChild&&ha[i].firstChild.data){
 if(ha[i].firstChild.data==bb[x+1]){
if(ha[i].onclick&&ha[i].onclick.toString().indexOf("P7_TMenu")>-1){ a=ha[i].parentNode;}else{a=ha[i].parentNode.parentNode; ha[i].className="p7currentmark";}while(a){ if(a.tagName&&a.tagName=="DIV"&&a.firstChild&&a.firstChild.tagName=="A"){ P7_TMenu(a.firstChild,1);}a=a.parentNode;}}}}}}}} }

2. Next, we'll need to tell the TMM system to use this function when loading the page, in addition to the the normal P7_TMopen() function. In source view, locate the <body> tag, onLoad event, it will look something like this:

<body onLoad="P7_TMclass();P7_TMopen()">

-Add the P7_TMfolder() function call just before the existing P7_TMopen() function, so it looks like this:

<body onLoad="P7_TMclass();P7_TMfolder();P7_TMopen()">

3. Lastly, we just need to define the parameters that the system will follow in order to open the appropriate menu section. We will define a set of folder name/text link pairs. If the page being loaded contains that folder name in its url then the script will open the menu to whichever link in the menu matches the link text value. This is done by simply editing the script to replace your actual folder names:

-Locate this line in the function:

var bb=new Array('folder1','text1','folder2','text2','folder3','text3','folder4','text4');

-Replace 'folder1' with the actual folder name that contains the page(s) to be loaded and replace 'text1' with the actual text contained in the link to which you want the menu to open. You can add or delete these folderName/textLinkValue pairs as you need. An actual system would look like something like this:

var bb=new Array('products','Our Products','support','Support Options','tutorials','Tutorials Listing');

This example will open the menu to the link, or menu section, whose link text is "Our Products" whenever a page's url contains the "products" folder, and will open the menu to the link, or menu section, whose link text is "Support Options" whenever a page's url contains the "support" folder, and will open the menu to the link, or menu section, whose link text is "Tutorials Listing" whenever the page's url contains the "tutorials" folder.

Note 1: If you are using the "text trigger" option, and you are specify one of the menu section triggers to be opened, then the plus sign (+) will be a part of the actual text link. Be sure to include the plus sign in the text Link value.

That's it! You now have an automated way of handling pages that do not appear in the menu without the need to make any specific settings on these pages.

 

Back to the questions list