Creating a Template

Creating the template

Now we must divide the code into two parts, the header and the footer. Basically, everything before the "Content goes here." placeholder is the header, and everything after it is the footer. Once you've broken the HTML code into these two parts, create a new ASP file and stub in two subroutines named Header and Footer, like this:

<% Sub Header(title) %>
<% End Sub %>

<% Sub Footer() %>
<% End Sub %>

You'll notice that the Header subroutine has one parameter, title. This is so we can pass the title of the page into the subroutine so that it can insert it into the template. Now put the HTML code into the subroutines. In the places where the title should go in the header, put instead the code <%=title%>.

<% Sub Header(title) %>
<html>
  <head>
    <title><%=title%></title>
  </head>
  <body>
    <table cellpadding="6" cellspacing="0" border="0">
      <tr>
        <td colspan="2" bgcolor="#aaaaff">
          <big><b><%=title%></b></big>
        </td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#aaaaff" nowrap>
          Nav 1<br>
          Nav 2<br>
          Nav 3
        </td>
        <td valign="top" bgcolor="white">
<% End Sub %>

<% Sub Footer() %>
        </td>
      </tr>
    </table>
  </body>
</html>
<% End Sub %>

It's often good practice to save templates and other files that are included by your pages in a separate directory. I called mine "include", so let's save our template as "/include/template.asp".

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The question of whether computers can think is just like the question of whether submarines can swim.” - Edsger W. Dijkstra