日期:2011-11-05  浏览次数:21135 次

index.asp
-----------------------------------------------------------------------
<!--#include file="templateclass.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 oTemplate
  .usetemplate("message.tpl")
  .tag("date") = Date()
  .tag("self") = "<div style='background:#dddddd'>" & .gettemplate("message.tpl",true) & "</div>"
  .tag("aspcode") = .gettemplate("index.asp",false)
  .tag("howtouse") = .gettemplate("howtouse.tpl",false)
  .display()
end with

set oTemplate = nothing
end sub
go()
%>

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, 1999
class template

  ' This variable stores the template
  private 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 string
    dim oFSO 'as object
    dim oTemplate 'as object
    dim temptemplate 'as string

    ' Open type for the template(read-only)
    const forreading = 1,boolcreatefile = false
    
    if IsNull(encodetohtml) or encodetohtml = "" or encodetohtml = false then
     encodetohtml = false
    else
     encodetohtml = true
    end if
    

    on error resume next
    ' Create filesystemobject
    set oFSO = server.createobject("scripting.filesystemobject")

        ' Create template object
        set oTemplate = oFSO.opentextfile(server.mappath(pathfilename),forreading,boolcreatefile)
          if err <> 0 then
            err.clear
            exit function
          end if
          ' Get the whole file as a string
          temptemplate = oTemplate.readall
          
          ' Encode template to HTML?
          if encodetohtml then
           gettemplate = tohtml(temptemplate)
          else
           gettemplate = temptemplate
          end if

          ' Close the template
          oTemplate.close

        ' Free the server resources
 &nb