Copy link to clipboard
Copied
I have a simple graphic menu with javascript mouseovers. I'm using cfinclude on all of my pages to include the menu. How do I get it to keep the mouseover graphic on that specific page. Is there a way to send a variable with cfinclude? Or should I be using a different tag?
URL variables do not make much sense.
I would normally just do something like this...
aPage.cfm
<cfset variables.thisPage = "aPage">
menuInclude.cfm
...<cfif variables.thisPage = "aPage">
<img src="/images/aPage.gif">
</cfelse>
<a href="index.cfm"><img src="/images/a_home2.gif" onmouseout="SwapHome()" onmouseover="SwapHomeOver()" name="image1" / border="0"></a>
</cfif>
<cfif variables.thisPage = "bPage">
<img src="/images/bPage.gif">
</cfelse>
<a href="index.cfm"><img src="/images/b_home2.gi
Copy link to clipboard
Copied
There is nothing to send...
As the name indicates, <cfinclued....> literally included the code from the indicated file at the point of the tag.
Thus it is included in the same response and shares all variables available at that point in the code.
So this works just as you would expect it to.
main.cfm
<cfset variables.foobar = "Just for fun">
<cfinclude template = "another.cfm">
another.cfm
<cfoutput>#variables.foobar#</cfoutput>
Copy link to clipboard
Copied
I'm not sure what the scope of your project is, but it sounds as if it may be easier to simply have an index or main.cfm that already contains your menu, and then call your individual files via cfinclude. That way, you wont have to include your menu on every page executed.
If you want your mouseover image to stick based on the page you are on, you will need write a statement surrounding your images that have a variable to check.
So example:
<cfif myPage EQ 2><img src="images/page2_mouseOver.gif"><cfelse><img src="images/page2.gif">
Copy link to clipboard
Copied
Right. So how do I send that variable to the menu?
Now the menu links just go to each page and each page has the menu included.
Example menu file included on each page:
<a href="index.cfm"><img src="/images/b_home2.gif"
onmouseout="SwapHome()" onmouseover="SwapHomeOver()" name="image1" / border="0"></a>
I could do that with a URL variable, right?
Change menu:
<a href="index.cfm?page=1"><cfif URL.page EQ 1><img src="/images/b_home3.gif"
onmouseout="SwapHome()" onmouseover="SwapHomeOver()" name="image1" / border="0"><cfelse><img src="/images/b_home2.gif"
onmouseout="SwapHome()" onmouseover="SwapHomeOver()" name="image1" / border="0"></cfif></a>
The problem is then I would have to add that variable to every link to every page.
Is there another way?
Copy link to clipboard
Copied
URL variables do not make much sense.
I would normally just do something like this...
aPage.cfm
<cfset variables.thisPage = "aPage">
menuInclude.cfm
<cfif variables.thisPage = "aPage">
<img src="/images/aPage.gif">
</cfelse>
<a href="index.cfm"><img src="/images/a_home2.gif" onmouseout="SwapHome()" onmouseover="SwapHomeOver()" name="image1" / border="0"></a>
</cfif>
<cfif variables.thisPage = "bPage">
<img src="/images/bPage.gif">
</cfelse>
<a href="index.cfm"><img src="/images/b_home2.gif" onmouseout="SwapHome()" onmouseover="SwapHomeOver()" name="image2" / border="0"></a>
</cfif>
There are innumerable variations on this depending on how exactly you want your menu to work but this gives you the basic idea.
Copy link to clipboard
Copied
That makes sense and is a whole lot easier.
Thank you.
Copy link to clipboard
Copied
Now that we have showed you how simple it is to share data between a template and an included template.
You coud use getBaseTemplatePath() to do the same thing without requring anybody to set data in the code.
aPage.cfm
<cfinclude tempate="menu.cfm">
menu.cfm
<cfif listLast(getBaseTemplatePath(),"\") EQ "aPage.cfm">
<!--- listLast(getBaseTemplatePath(),"\") will return 'aPage.cfm" for the above code --->
<img...>
<cfelse>
<a...>
</cfif>
Copy link to clipboard
Copied
So, I've finally got back around to trying the other way you suggested, and I can't seem to get it to work without using
<cfif #Right(listLast(getBaseTemplatePath()), 13)# EQ "contactus.cfm"> <img...> <cfelse> <a...> </cfif>
When I output listLast(getBaseTemplatePath()) it gives me the whole URL. Am I doing this wrong?
Thanks again for all of your help.
Date: Wed, 29 Apr 2009 10:32:23 -0600
From: forums@adobe.com
To: dooleymort@hotmail.com
Now that we have showed you how simple it is to share data between a template in an included template.
You coud use getBaseTemplatePath() to do the same thing without requring anybody to set data in the code.
aPage.cfm
<cfinclude tempate="menu.cfm">
menu.cfm
<cfif listLast(getBaseTemplatePath()) EQ "aPage.cfm">
<!--- listLast(getBaseTemplatePath()) will return 'aPage.cfm" for the above code --->
<img...>
<cfelse>
<a...>
</cfif>
>
Copy link to clipboard
Copied
Somehow I didn't include what I was using:
Right(listLast(getBaseTemplatePath()), 13) for contactus.cfm page
Date: Wed, 29 Apr 2009 10:32:23 -0600
From: forums@adobe.com
To: dooleymort@hotmail.com
Now that we have showed you how simple it is to share data between a template in an included template.
You coud use getBaseTemplatePath() to do the same thing without requring anybody to set data in the code.
aPage.cfm
<cfinclude tempate="menu.cfm">
menu.cfm
<cfif listLast(getBaseTemplatePath()) EQ "aPage.cfm">
<!--- listLast(getBaseTemplatePath()) will return 'aPage.cfm" for the above code --->
<img...>
<cfelse>
<a...>
</cfif>
>