Click to See Complete Forum and Search --> : Creating the title of a page with ASP...


Ark86
01-02-2003, 11:49 PM
For my website, I use SSI to include my header and footer asp files. I have the rest in the middle. I want to create different titles for each page, but the title tag is in my header file so it has to be the same all of the time. I would like to use ASP to solve this. In the header I was thinking of putting in this code:

<title>
<%
Response.write title
%>
</title>

And in my page this code:

<%
Dim title="News"
Response.write title
%>


But it doesn't work because the variable is declared after the time I want to write it. How should I go about this? Thanks.

FMRock
01-03-2003, 05:27 PM
Could put some logic in the header itself

or you could but the title thing above the header...


<%
Dim Title="News"
%>
<!--#include file="incheader.asp"-->

-----Body goes in here------


<!--#include file="incfooter.asp"-->

Ark86
01-03-2003, 10:58 PM
Could put some logic in the header itself
Well, I include the header in every one of my pages so it would say "News" on every page. I was thinking about putting the name of the asp file and the title I want associated with it in a 2-dimensional array. I could then put the title in by using Request.ServerVariables("Script_Name"). (I think that might work. I just found out about that ServerVariables thing today). Will that work? Is there a simpler way? Thanks.

FMRock
01-04-2003, 01:22 AM
You could do it either way... you could write some logic to display the title you want depending on the script name... or the way I showed you could just change that varible name above the incheader .. something like this


<%
varTitle="Title for Page 1"
%>
<!--#include file="incheader.asp"-->

-----Body goes in here------


<!--#include file="incfooter.asp"-->


and another page would be something like


<%
varTitle="Title for Page 2"
%>
<!--#include file="incheader.asp"-->

-----Body goes in here------


<!--#include file="incfooter.asp"-->



I have also used the server variable to get the script name... and then display a certian title depending on which script you are on. Both are pretty simple to do.

Grizzly
01-04-2003, 02:13 AM
Unfortunately my lack of experience with ASP prevents me from giving you any concrete advice, but I can tell you from other languages I've worked with that output buffering is usually the best way to handle situations such as these.

Anytime I develop a web app, I use an architecture such that the "content" of the page itself is evaluated first, and then the "layout" is applied, or "wrapped" around that content as an after-thought. Taking that approach allows you to quickly and easily change the layout, menus, title, etc, depending on which page you happen to be viewing. Output buffering is one way you can parse content before layout.

ASP is a fairly versitile language from what I understand, so I would imagine that there is some method or approach that allows you to use output buffering.

Just my two cents :p If anyone here knows more about leveraging output buffering in ASP, definitely give a shout out.

Ark86
01-04-2003, 11:41 AM
You could do it either way... you could write some logic to display the title you want depending on the script name... or the way I showed you could just change that varible name above the incheader .. something like this
OK, sorry. I didn't realize you had put that above the include statement. I see what you mean now. I will give that a try. Thanks.

Edit: OK, I tried it and it works great. Thanks.

FMRock
01-04-2003, 01:06 PM
Well im glad that worked for you.. you could also do something like this if you wanted to keep it all in the header.


<%
varCurrentPage = LCase(request.servervariables("SCRIPT_NAME"))
If varCurrentPage = "/test1.asp" Then
varTitle = "Title For Page 1"
End If
If varCurrentPage = "/test2.asp" Then
varTitle = "Title For Page 2"
End If
%>
<html>
<head>
<title><%=varTitle%></title>
</head>


Grizzly,
Im interested in the output buffering stuff, and ill google it shortly.

Usually the way i create my header and footers usually have the title, navigation,menus ect In the header. And only the stuff between the header and footer for each page is different. That way the main content of the page is wrapped by the header and footer.

Ark86
01-04-2003, 04:32 PM
<%
varCurrentPage = LCase(request.servervariables("SCRIPT_NAME"))
If varCurrentPage = "/test1.asp" Then
varTitle = "Title For Page 1"
End If
If varCurrentPage = "/test2.asp" Then
varTitle = "Title For Page 2"
End If
%>
<html>
<head>
<title><%=varTitle%></title>
</head>

That is similar to what I was thinking of doing, but it would take A LOT of if statements if I am going to add a lot of pages to my website. I was thinking of doing it in a for...next loop. But the way you mentioned earlier works better and is much simpler.

Ark86
01-06-2003, 10:49 PM
Unfortunately my lack of experience with ASP prevents me from giving you any concrete advice, but I can tell you from other languages I've worked with that output buffering is usually the best way to handle situations such as these.

Anytime I develop a web app, I use an architecture such that the "content" of the page itself is evaluated first, and then the "layout" is applied, or "wrapped" around that content as an after-thought. Taking that approach allows you to quickly and easily change the layout, menus, title, etc, depending on which page you happen to be viewing. Output buffering is one way you can parse content before layout.

ASP is a fairly versitile language from what I understand, so I would imagine that there is some method or approach that allows you to use output buffering.

Just my two cents If anyone here knows more about leveraging output buffering in ASP, definitely give a shout out.

When reading my book on ASP (yawn) I saw something that sounded like what you are talking about. There is 4 methods that let you control when the data is sent to the HTML stream. They are:

Response.buffer=true (to enable buffer)
Response.flush (to send previous code)
Response.clear (to clear any data back to the last flush)
Response.end (to end the output)

That sounds like what you are talking about. Am I right?

Grizzly
01-07-2003, 12:00 AM
Yeah, those response methods allow you to control the the output buffer alright.

But that's only one part of the equation. I would imagine that there are folks out there that have documented best practices, or even full-blown architectures for leveraging ASP's output buffering capabilities against common layout issues (such as dynamic titles, menus, layouts, etc)