Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to cfinclude different images on header?

Status
Not open for further replies.

shearak

Programmer
Aug 22, 2001
9
0
0
US
I need to include a header for every page with a different image based on the page. How can I do this without having to make a separate CFInclude header for every page with a different image header.

Please advise,

Thanks
 
Hello Shearak!

As I am sure you'll find out, there are many ways to skin the cat, this is what I figure is as easy as a novice like me can suggest.

A) setup a table where you will identify your page and its corresponding image
B) on top of templates, <cfinclude url=&quot;getImage.cfm&quot;>
C) within getImage.cfm, use CGI_ variable to identify which page you're loading. Once page has been successfully identified, you can
D) lookup page on table and if found, show its header image; if not found, show your default image (safety net)


notice that CGI_ variable will have full path, you might need to strip absolute path to obtain ONLY actual template name (probably using cflist ... or something that will allow to split string based on a command character, in this case the / ).

OR, instead of using CGI_ variable, you can cheat and define a session.variable (session.PageName) just before you <cfinclude url=&quot;getImage.cfm&quot;> thus allowing getImage.cfm to reference session variable.

Good luck!


Jose Lerebours If you have the knowledge, consult and educate those who need it! - Jose Lerebours
 
You can use the cfif

For instance you can use any type of the debugging output/ cgi variables.

If you were on a page like

index.cfm?page=home you could do

<cfif findnocase(&quot;page=home&quot;,query_string)>
img 1
<cfelseif findnocase(&quot;page=about&quot;,query_string)>
img 2
</cfif>
 
Hello Sammut!

The problem with <cfif ...> is that it is &quot;hard coded&quot;. If anything should change (page name, image name and or location), you will need to change program(s) as well.

Regards;

josel If you have the knowledge, consult and educate those who need it! - Jose Lerebours
 
I see what you could mean with cfif, but if you creat a dynamic header and footer wrapper and place your switches or conditionals in there, then there is only one central file to use.
 
Sammut,
Could you explain this again. I am not really following.

index.cfm?page=home you could do

<cfif findnocase(&quot;page=home&quot;,query_string)>
img 1
<cfelseif findnocase(&quot;page=about&quot;,query_string)>
img 2
</cfif>

Thanks again,
shearak
 
What we did was even simpler...

The Side navigation is called based on a hard coded value assigned to the top of each page. It calls a side include that also has a sub nav call to decide which subsection it should drop down.

Works like a champ...

The other way is to do somthing like this...


<cfif CGI.HTTP_REFERER contains &quot;services&quot;>
<CFSET Header_Image = &quot;Services.jpg&quot;>
<cfelseif CGI.HTTP_REFERER contains &quot;portfolio&quot;>
<CFSET Header_Image = &quot;portfolio.jpg&quot;>
</cfif>

If you have a lot of Ifs... just use a CFSWITCH instead.


The above checks for the name &quot;services&quot; anywhere in the page path... folder, file, querystring, anything...

I would recommend the hard coded value instead of the above for more control. You could define the Page title name and look for that...

Anyway... hope that this helps...
I do not like the idea of the image dependent on a query string.
If they modify it... you have a broken page.image. Not very professional.

:)


-- David McIntosh
 
Query string is only an example. You can use almost any cgi var. If your site is dynamic using the query_string tests quite fast and well. You could also pass url or test for attributes in len(). I would not gauge this on professional or unprofesional. Code is gauged on how it works. With that said you can also test on the HTTP_REFERER, but the contains clause I belive takes longer to process.

Or typical scenario is a modified fusebox. In this case if the query string is modified without being passed through index.cfm, then they page defaults to home. Here is an example of how we dynamically include or exclude content. This is a dsp_header:

<!--- Begin header --->
<cfoutput>
<html>
<head>
<title>#attributes.pageTitle#</title>
<cfinclude template=&quot;dsp_meta.cfm&quot;>
<script language=&quot;JavaScript&quot; src=&quot;#js#/clientsniff.js&quot; type=&quot;text/javascript&quot;></script>
<script language=&quot;JavaScript&quot; src=&quot;#js#/popupwindow.js&quot; type=&quot;text/javascript&quot;></script>
<script language=&quot;JavaScript&quot; src=&quot;#js#/popupwindow2.js&quot; type=&quot;text/javascript&quot;></script>
<script language=&quot;JavaScript&quot; src=&quot;#js#/checkbox.js&quot; type=&quot;text/javascript&quot;></script>
<cfif findnocase(&quot;my.register&quot;,query_string)>
<script language=&quot;JavaScript&quot; src=&quot;#js#/password.js&quot; type=&quot;text/javascript&quot;></script>
</cfif>
<cfif findnocase(&quot;my.charities&quot;,query_string)>
<script language=&quot;JavaScript&quot; src=&quot;#js#/confirm.js&quot; type=&quot;text/javascript&quot;></script>
</cfif>
<script type=&quot;text/javascript&quot;>
function toAnchor(anchorName)
{
if(location.href.split(&quot;##&quot;))
location.href = location.href.split(&quot;##&quot;)[0] + &quot;##&quot; + anchorName;
else
location.href = location.href + &quot;##&quot; + anchorName;
}
</script>
..........and so on


<!--- Giving Calc --->
<cfif findnocase(&quot;givingcalc&quot;,query_string)>
<script language=&quot;JavaScript1.2&quot; src=&quot;../_js_/calc/calc.js&quot;></script>
</cfif>
<!--- /Giving Calc --->

<link rel=&quot;stylesheet&quot; href=&quot;#css#/#request.MainCSS#&quot; type=&quot;text/css&quot;>
</head>

<body marginheight=&quot;0&quot; marginwidth=&quot;0&quot;#iif(Len(attributes.onload),DE(&quot; onload=&quot;&quot;&quot;&attributes.onload&&quot;&quot;&quot;&quot;),DE(&quot;&quot;))#>
<table width=&quot;765&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; height=&quot;100%&quot;>
<!--- height=&quot;100%&quot; moved here see below comment --->
<tr>
<td bgcolor=&quot;999999&quot; align=&quot;center&quot; valign=&quot;top&quot; width=&quot;165&quot;>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; >
<!--- removed height=&quot;100%&quot; look over site to make sure page still is 100% no matter the content size. See above--->
<tr>
<td bgcolor=&quot;000066&quot; valign=&quot;top&quot; align=&quot;right&quot;><a href=&quot;#attributes.BaseURL#&quot;><img src=&quot;_gfx_/images/logo1.gif&quot; width=&quot;165&quot; height=&quot;160&quot; alt=&quot;Charity Navigator&quot; border=&quot;0&quot;></a></td>
</tr>
<tr>
<td bgcolor=&quot;336699&quot; align=&quot;center&quot; valign=&quot;middle&quot; height=&quot;28&quot; class=&quot;welcome&quot;>
<!--- Logged in or Out --->
<cfif isdefined(&quot;client.user.status&quot;) and client.user.status is 1>
<b><a href=&quot;#attributes.BaseURL#/?bay=my.charities&quot; class=&quot;welcome&quot;>Review #client.user.fname#'s Charities</a></b><br>
(Not #client.user.fname#? <a href=&quot;#attributes.BaseURL#/?bay=my.logout&quot; class=&quot;welcome&quot;>Click here</a>)
<cfelse>
<a href=&quot;#attributes.BaseURL#/?bay=my.login&quot; class=&quot;welcome&quot;>Log In or Join</a>
</cfif>
<!--- /Logged in or Out --->
</td>
</tr>
</table>
<cfif findnocase(&quot;search.adv&quot;,query_string)>
<!--- nada --->
<cfelse>
<cfinclude template=&quot;../search/dsp_sidesearch.cfm&quot;>
</cfif>
<br>
<cfinclude template=&quot;dsp_factoid.cfm&quot;>

<br>
<cfif not findnocase(&quot;bay&quot;,query_string)>
<!---ONLY HOME PAGE --->

<!--- Poll --->
<cfinclude template=&quot;inc_poll.cfm&quot;>
<!--- /Poll --->
<br>
<!--- Mail --->
<cfinclude template=&quot;inc_email.cfm&quot;>
<!--- /Mail --->
<p> </p>

<!--- /ONLY HOME PAGE --->
</cfif>

</td>


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top