Creating the title of a page with ASP...

Sharky Forums


Results 1 to 10 of 10

Thread: Creating the title of a page with ASP...

  1. #1
    Tiger Shark Ark86's Avatar
    Join Date
    Aug 2001
    Location
    Ohio
    Posts
    924

    Creating the title of a page with ASP...

    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.
    My Webpage: http://www.andyknotts.com (Give me feedback)

    My specs:
    ----------------
    AMD Athlon XP 2500+ OC'd to 2100MHz
    Abit NF7 @ 205 MHz FSB
    1.5Gigs PC3200 RAM @410Mhz
    Turtle Beach Santa Cruz
    Altec Lansing 641's
    128meg NVidia 6600GT AGP
    7200rpm 120G w/ WinXP pro
    5400rpm 40G w/ Gentoo Linux
    NEC DVD/RW
    Lite-on 40x12x48 CDRW
    19" Hyundai L90D+ LCD (amazing )

  2. #2
    Catfish
    Join Date
    Sep 2001
    Location
    Ft Myers FL
    Posts
    236
    Could put some logic in the header itself

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

    Code:
    <%
    Dim Title="News"
    %>
    <!--#include file="incheader.asp"-->
    
    -----Body goes in here------
    
    
    <!--#include file="incfooter.asp"-->
    Last edited by FMRock; 01-03-2003 at 06:27 PM.
    MSI K7T266 Pro2,AMD XP1600,Volcano 6CU+
    Crucial 512 MB PC2100,Min Maw Case
    WD 100 Gig HD,GF2
    -------------------------------------
    Dell Inspiron 8200. P4 1.7 384mb, 30 gig HD, ATI Radeon 9000

  3. #3
    Tiger Shark Ark86's Avatar
    Join Date
    Aug 2001
    Location
    Ohio
    Posts
    924
    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.
    My Webpage: http://www.andyknotts.com (Give me feedback)

    My specs:
    ----------------
    AMD Athlon XP 2500+ OC'd to 2100MHz
    Abit NF7 @ 205 MHz FSB
    1.5Gigs PC3200 RAM @410Mhz
    Turtle Beach Santa Cruz
    Altec Lansing 641's
    128meg NVidia 6600GT AGP
    7200rpm 120G w/ WinXP pro
    5400rpm 40G w/ Gentoo Linux
    NEC DVD/RW
    Lite-on 40x12x48 CDRW
    19" Hyundai L90D+ LCD (amazing )

  4. #4
    Catfish
    Join Date
    Sep 2001
    Location
    Ft Myers FL
    Posts
    236
    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

    Code:
    <%
    varTitle="Title for Page 1"
    %>
    <!--#include file="incheader.asp"-->
    
    -----Body goes in here------
    
    
    <!--#include file="incfooter.asp"-->
    and another page would be something like

    Code:
    <%
    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.
    MSI K7T266 Pro2,AMD XP1600,Volcano 6CU+
    Crucial 512 MB PC2100,Min Maw Case
    WD 100 Gig HD,GF2
    -------------------------------------
    Dell Inspiron 8200. P4 1.7 384mb, 30 gig HD, ATI Radeon 9000

  5. #5
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077
    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.

  6. #6
    Tiger Shark Ark86's Avatar
    Join Date
    Aug 2001
    Location
    Ohio
    Posts
    924
    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.
    Last edited by Ark86; 01-04-2003 at 12:51 PM.
    My Webpage: http://www.andyknotts.com (Give me feedback)

    My specs:
    ----------------
    AMD Athlon XP 2500+ OC'd to 2100MHz
    Abit NF7 @ 205 MHz FSB
    1.5Gigs PC3200 RAM @410Mhz
    Turtle Beach Santa Cruz
    Altec Lansing 641's
    128meg NVidia 6600GT AGP
    7200rpm 120G w/ WinXP pro
    5400rpm 40G w/ Gentoo Linux
    NEC DVD/RW
    Lite-on 40x12x48 CDRW
    19" Hyundai L90D+ LCD (amazing )

  7. #7
    Catfish
    Join Date
    Sep 2001
    Location
    Ft Myers FL
    Posts
    236
    Well im glad that worked for you.. you could also do something like this if you wanted to keep it all in the header.

    Code:
    <%
     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.
    MSI K7T266 Pro2,AMD XP1600,Volcano 6CU+
    Crucial 512 MB PC2100,Min Maw Case
    WD 100 Gig HD,GF2
    -------------------------------------
    Dell Inspiron 8200. P4 1.7 384mb, 30 gig HD, ATI Radeon 9000

  8. #8
    Tiger Shark Ark86's Avatar
    Join Date
    Aug 2001
    Location
    Ohio
    Posts
    924
    <%
    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.
    My Webpage: http://www.andyknotts.com (Give me feedback)

    My specs:
    ----------------
    AMD Athlon XP 2500+ OC'd to 2100MHz
    Abit NF7 @ 205 MHz FSB
    1.5Gigs PC3200 RAM @410Mhz
    Turtle Beach Santa Cruz
    Altec Lansing 641's
    128meg NVidia 6600GT AGP
    7200rpm 120G w/ WinXP pro
    5400rpm 40G w/ Gentoo Linux
    NEC DVD/RW
    Lite-on 40x12x48 CDRW
    19" Hyundai L90D+ LCD (amazing )

  9. #9
    Tiger Shark Ark86's Avatar
    Join Date
    Aug 2001
    Location
    Ohio
    Posts
    924
    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?
    My Webpage: http://www.andyknotts.com (Give me feedback)

    My specs:
    ----------------
    AMD Athlon XP 2500+ OC'd to 2100MHz
    Abit NF7 @ 205 MHz FSB
    1.5Gigs PC3200 RAM @410Mhz
    Turtle Beach Santa Cruz
    Altec Lansing 641's
    128meg NVidia 6600GT AGP
    7200rpm 120G w/ WinXP pro
    5400rpm 40G w/ Gentoo Linux
    NEC DVD/RW
    Lite-on 40x12x48 CDRW
    19" Hyundai L90D+ LCD (amazing )

  10. #10
    Ursus Arctos Moderatis Grizzly's Avatar
    Join Date
    Sep 2000
    Location
    Providence, RI USA
    Posts
    3,077
    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •