Index.asp ------------------------------------------------- ------------------------- <% 'this is the code used to load And Display The Template. 'See How Clean IT IS !!! :) Sub Go () Dim Otemplate
Set Otemplate = New Template
With teemplate.useTemplate ("message.tpl"). Tag ("Date") = Date (). Tag ("Self") = "
Set Otemplate = Nothingend Subgo ()%>
TemplateClass.asp ----------------------------------------------- ------------------------- <% 'this is the template Object. It allows the creation, reading' and editing of templates on the server. ' Created by: Christopher Brown-Floyd 'Date: November 3, 1999Class Template
'This variable stores the templateprivate mytemplate' AS STRING
'This method gets a template from the server and returns' the whole file as a string.public function gettemplate (pathfilename, encodetohtml) 'as stringdim oFSO' as objectdim oTemplate 'as objectdim temptemplate' as string
'Open type for the template (read-only) const forreading = 1, boolcreatefile = false
If isnull (encodetohtml) or encodetohtml = "" or encodetohtml = false burodetohtml = falseelseencodetohtml = trueEnd IF
On Error ResMject 'Create FileSystemObjectSet OFSO = Server.createObject ("scripting.filesystemObject")
'Create template objectset oTemplate = oFSO.opentextfile (server.mappath (pathfilename), forreading, boolcreatefile) if err <> 0 thenerr.clearexit functionend if' Get the whole file as a stringtemptemplate = oTemplate.readall 'Encode template to HTML? If Encodetohtml ThengetTemplate = Tohtml (TempTemplate) ElsegetTemplate = TempTemplateEnd IF
'Close the TemplateTemplate.Close
'Free the server resourcesset teemplate = Nothing
Set ofso = nothingend function
'This Procedure Gets and Stores A TemplatePublic Sub UseTemplate (PathFileName) thistemplate = getTemplate (PathfileName, False) End Sub
'This Property Replaces Tags with the user's templatepublic Property Let Tag (Tagname, UserString) Dim LD, RD' AS Stringdim Temptag 'AS Stringdim TagStart, TAGEND' AS INTEGER
LD = "" tagstart = 1
do while tagstart> 0 and tagstart
Public Sub Removetags () Dim LD, RD 'As Stringdim Temptag' AS Stringdim TagStart, TAGEND 'AS INTEGER
LD = "" tagstart = 1
do while tagstart> 0 and tagstart
'This Property Returns The Current TemplatePublic Property Get thistemplate ()' as stringthistemplate = MyTemplateEnd Property
'This subroutine displays the current templatepublic sub displet () Response.write thistemplateend Sub
'This subroutine encodes the current template to htmlpublic sub htmlencode () TOHTML (thistemplate) End Sub
'This Procedure Saves The Current Template To The Serverpublic Sub Saves (PathfileName) DIM OFSO' As Objectdim Otemplate, OBACKUP 'As Objectdim StRTRUEPATH' AS STRING
'Open type for the template (read-only) const forreading = 1, forwriting = 2, boolcreatefile = true
ON Error ResMe next
'Create FileSystemObjectSet OFSO = Server.createObject ("Scripting.FileSystemObject")
'Create template objectstrTruePath = server.mappath (pathfilename) if oFSO.fileexists (strTruePath) thenoFSO.copyfile strTruePath, strTruePath & ".bak", trueend ifset oTemplate = oFSO.opentextfile (strTruePath, forwriting, boolcreatefile) if err <> 0 thenerr .cleArExit Subend if 'Write The Whole Template to the ServeroteMplate.write thistemplate
'Close the TemplateTemplate.Close
'Free the server resourcesset teemplate = Nothing
Set ofso = nothingend sub
'This function encodes text to htmlprivate function tohtml (temptemplate) temptemplate = replace (temptemplate, "<", "<") temptemplate = replace (temptemplate, "", "") temptemplate = replace (temptemplate, vbcrlf, "
")
TOHTML = TempTemplateEnd Function
'This procedure clears the variable what the current template' is stored in when the object is created.private sub coplass_initialize () mytemplate = "" End Sub
'This procedure clears the variable what the current template' is stored in When a object is terminated.private sub class_terminate () set mytemplate = nothingnd suend class%>
Howtouse.tpl ------------------------------------------------- -------------------------
thistemplate b> = string i> loads a dynamically built template infa Template Object . Use this methodwhen there isn't a file to read from. P> div>
tag ( tag name as string i>) b> = string i> Replaces All Occurrence of a Tag with the specified string. p>
variable i> = getTemplate ( Path as string i> , [Encode to HTML] As Boolean i>) b> returns the template from the specified path; however, it isn't loading into the object. p> div>
useemplate ( path as string i>) b> loads the template from the specified Path Into the Object. p>
htmlencode () b> EncoDes the current template loaded Into HTML. P>
display () b> Writes the current template to the user's brohing. p>
removetags () b> removes all tags what have't been replaced. p>
saveas () b> saves the current template to the specified path. Use this method when Youwant to save the change: if a Template.note: if A FILE OF THE SAME NAME EXISTS At the Specified Path, ".bak" Will Beadded to the end of its name; thus "myfile.tpl" would be "myfile.tpl.bak". p> div> Div>
Message.tpl --------------------------------------------- -------------------------
this is an example of how to use my template class.dynamic data for your Template can come from anywhere.IT can come from a built-in asp function: it can come from a file:
You can Even Use IT As an Online Source Editing Tool For Your ASP Code: