Site menu include

I would like to include my main menu in the different pages using either <cfinclude> or <custom_tag>, rather than having it hard coded in each page as it is now! My problem, though, is not how to use <cfinclude> or <custom_tag> but in the fact how I should declare a current page for each menu item when on that particular page, which I now accomplish using CSS


<a href="#" class="current">

which I can use since the menu is hard coded in each page. I’m breaking my head :headbang: on how to reach the same result when the menu is included.

Any ideas?

<CFSET variables.thispage = GetFileFromPath(GetCurrentTemplatePath())>

<a href="<CFIF variables.thispage EQ "home.html"># class="current"<CFELSE>home.html</CFIF>">Home</a>
<a href="<CFIF variables.thispage EQ "about.html"># class="current"<CFELSE>about.html</CFIF>">About</a>
<a href="<CFIF variables.thispage EQ "contact.html"># class="current"<CFELSE>contact.html</CFIF>">Contact</a>

Hi rudy. That is what I was thinking, but it isn’t doing what I expected? In other words it doesn’t give me the current state when on the desired page. This what I have:


<a href="index_eng.cfm"  <cfif variables.thispage Eq "index_eng.cfm"> class="current tab1" <cfelse> class="tab1" </cfif> >Homepage</a>

Anyone see what is wrong with this?

Thank you in advance

Little update on this one. I can’t get the

<cfset variables.thispage = GetFileFromPath(GetCurrentTemplatePath())>

<a href="<cfif variables.thispage Eq "index_eng.cfm">index_eng.cfm" class="current tab1" <cfelse> index_eng.cfm" class="tab1" </cfif>">Homepage</a>

to work. Whenever I add the class current to the class behind the <cfelse> the current class is working, but remains in that state. So maybe the GetFileFromPath is not the right way to tackle this. Any other suggestions are more than welcome

huh?

are you describing a css problem or a coldfusion problem?

Since:


<cfset variables.thispage = GetFileFromPath(GetCurrentTemplatePath())>
 
<a href="<cfif variables.thispage Eq "index_eng.cfm">index_eng.cfm" class="current tab1" <cfelse> index_eng.cfm" class="tab1" </cfif>">Homepage</a>

results in what I described in my former post, I presume it’s a Coldfusion problem. I.O.W. Behind the <cfelse> would mean that I’m not on that particular page(index_eng.cfm) right? But when I use:

<cfelse> index_eng.cfm" class="current tab1" </cfif>

it set the homepage tab to current so it’s obviously the GetFileFromPath that isn’t working!

why would you put “current” on the CFELSE part?

I wouldn’t I mentioned that to indicate that

<cfif variables.thispage Eq "index_eng.cfm">

wasn’t working properly, I.O.W was only seeing the part behind the <cfelse>. What did the trick though was using IS instead of Eq


<cfif CurrentPage IS "index_eng.cfm">

and now it works fine

that’s just weird

they’re supposed to be the same thing

i’ve been using EQ for years and it ~always~ works the way you’d expect

there’s gotta be a reason why your “Eq” appeared not to work

i don’t imagine it’s the capitalization, either

I really don’t know Rudy! Anyway it’s working now and you pointed me in this direction. Thank you for that :slight_smile:

This might be useful for someone else. I have adjusted this somewhat.


<li><a href="index.cfm" class="#IIF( page_id IS '1', DE( 'tab1 current' ), DE( 'tab1' ))#">Homepage </a></li>

And each page has a page_id, This makes the coding way shorter, and easier to read.