Complex ASP Template 1.5 Demo

This slightly more complex demo illustrates how to use the ASP Template class to separate code and content. In this example the template file references three other templates:

[%header%]
[%body%]
[%footer%]

These templates essentially contain the same HTML from the simple demo, except they have it broken down into a header, text, and footer portions. The HTML in these three templates is:

--- The HTML in the Header Template ----
<!--header.html-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
	<title>[%title%]</title>
</head>

<body bgcolor="#FFFFFF">
[%date%]<br>
<hr>


--- The HTML in the Body Template ----
<!--text.html-->
This text will appear in the body of the page... 
And it will not be parsed for any tokens like this one: [%date%]
(<i>This is because we are using type INCLUDEANDNOPARSE when loading the body template...</i>)



--- The HTML in the Footer Template ----
<!--footer.html-->
</body>
</html>

As in the simple demo the token date is replaced by formatdatetime(now(), 3); the token title is replaced by ASP Templates [1.5] Simple; and, finally, the template images is replaced by /demos/asptemplates/templates/Simple/images/. The output can be seen below. (Note that the delimited tags in the Body template (i.e., [% date %]) are not parsed because when adding the token, a type of INCLUDEANDNOPARSE is used, which specifies that the template should be included, but not parsed...)


ASP Templates [1.5] Complex 9:11:24 AM


This text will appear in the body of the page... And it will not be parsed for any tokens like this one: [%date%] (This is because we are using type INCLUDEANDNOPARSE when loading the body template...)


Source Code

<!--#INCLUDE file="includes/template_cls.asp"-->
<%
dim objTemplate
const TMPLDIR = "/demos/asptemplates/templates/Complex/tmpl/"
const IMGDIR = "/demos/asptemplates/templates/Complex/images/"
set objTemplate = new template_cls
with objTemplate
	.TemplateFile = TMPLDIR & "template.html"
	.AddToken "date", STRINGVARIABLE, formatdatetime(now(), 3)
	.AddToken "title", STRINGVARIABLE, "ASP Templates [1.5] Complex"
	.AddToken "header", INCLUDEANDPARSE, TMPLDIR & "header.html"
	.AddToken "footer", INCLUDEANDPARSE, TMPLDIR & "footer.html"
	.AddToken "body", INCLUDEANDNOPARSE, TMPLDIR & "text.html"
	.AddToken "images", STRINGVARIABLE, IMGDIR
	.parseTemplateFile
end with
set objTemplate = nothing
%>


[View the simple.asp demo] | [View the ReallyComplex.asp demo] | [Return to the article]