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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Different Page Title From One ?nclude File

Status
Not open for further replies.

makemusic

Programmer
Apr 3, 2004
43
Hi...

ASP newbie here so a VERY simple problem which I am sure one of you could solve in two seconds.

I have an include file for my page header that is included on multiple pages but I want to display different page titles for each page. So my home.asp page should say 'Home' at the top of the page and my contacts.asp page should say 'Contacts' at the top of the page. I only want to use one include file so how do I get my code to work out which page is being served up and therefore which page title to display?

Am I looking at basic query strings?

Any help would be appreciated as at the moment Im using multiple include files unecessarily.

Thanks!
 
if you are at all interested in being found in search engines your title is the most important so "home", "contact" etc is of no use.

A quick way do what you want is to declare and set a variable for the title in each page before the include, then use the variable between the title tags.

Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Hi Chris

this has nothing to do with search engines. My page names were just examples.

I just want to know how I serve up different page headings for different pages using the same include file. As I said i have no idea about query strings etc so im just looking for a simple solution (with some example code). I think you may be correct about declaring a variable etc but i dont know how to do this unfortunately!
 
something along these lines (adapt to suit)

top of each page;
Code:
<%
dim strTitle
strTitle = "Something for the title"
%>
<!--#include virtual="/include_file.asp"-->

then modify the include file title code to be
<title><%=strTitle%></title>


Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
I generally make my header and footers Funcitons, so that you cold easily modify them to take arguments for Title, meta data, etc.

basically my headerfooter include file looks somehting like:
Code:
Function ShowHeader(hTitle,mKeywords, mDescription, bArgs)
   %>
   <html>
   <head>
   <title><%=hTitle%>
   <meta name="keywords" content="<%=mKeywords%>">
   <meta name="description" content="<%=mDescription%>">
   <link rel="stylesheet" href="_inclues/sample.css" type="text/css">
   </head>
   <body <%
   If Len(bArgs) > 0 Then Response.Write bArgs
   %>>
   <!-- pretty html header here -->
   <%
End Function

Function ShowFooter()
   %>
   <!-- Pretty footer here -->
   <a href="whatever.asp">Copyright Statement</a>
   </body>
   </html>
   <%
End Function

Other possible arguments or additional tags in the header inclde things like script tags to include js fils, etc. Depens on the site I am doing and such.

-T

barcode_1.gif
 
Thanks for your replies guys. I'm gonna have a play with the code later. Appreciate your time.
 
also, you can use request.servervariables("Script_Name") in the include, since the include isn't "called" individually (ie : ) it will never be the script name returned, so whatever page you call it from will be the script name.

seems you just want the page title to reflect the name of the script minus the .asp :
Code:
<%
' this code is tested.
PageName = Request.ServerVariables("Script_Name")
' the following is using split to just break away all the extraneous url info
PageTitleArr = Split(PageName,".")
PageTitleArr2 = Split(PageTitleArr(0),"/")
PageTitle = PageTitleArr2(Ubound(PageTitleArr))
%>
<title><%=PageTitle%></title>
you may want to look into some of the threads here about ProperCase ( search ) or Capitalizing words that way it doesn't just spit out a lowercase page title.

simple layout of the interaction of the above code :
/Includes/Title.inc
Code:
<%
PageName = Request.ServerVariables("Script_Name")
PageTitleArr = Split(PageName,".")
PageTitleArr2 = Split(PageTitleArr(0),"/")
PageTitle = PageTitleArr2(Ubound(PageTitleArr))
Response.Write "<title>" & PageTitle & "</title>" & vbcrlf
%>


PageWhatever.asp
Code:
<html>
<head>
<!--#include virtual="/includes/title.inc"-->
</head>
<body>
Blah
</body>
</html>

hope that helps

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
forgot to mention the reason for the second split in the title code is to strip off all the extra sub folder stuff ( if it's there ) so if you have home.asp it'sll return "home" and /inventory/products/sometool.asp will return "sometool" instead of "/inventory/products/sometool"



[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top