FileName: awa_temp. Class.asp
Copy Code code as follows:
<%
' Crazy Frog! Template Action Class
' Author crazy~ frog! qq:379969387 Welcome to the Exchange
' Version V1.0;
Class awatemp
Public AA
Private fso,strtemp,filedata,getdatas,strhtmlname,htmlwrite,strlabel,strlvalues
'===========================================
' Constructor _ Initialize the FSO component
'===========================================
Private Sub Class_Initialize ()
Set fso=server.createobject ("Scripting.FileSystemObject")
End Sub
'===========================================
' destructor function _ Destroy FSO component
'===========================================
Private Sub Class_Terminate ()
Set fso=nothing
End Sub
'===========================================
' Class Property
'===========================================
' Version information
Public Property Get Version
version= "crazy~ Frog!" Template Action Class! V1.0 version; "
End Property
' Get template address and name
Public Property Let Temp (ByVal Values)
Strtemp=values
End Property
' Get the file name of the generated file
Public Property Let HTMLName (ByVal Values)
Strhtmlname=values
End Property
' Get tag
Public Property Let Label (ByVal Values)
Strlabel=values
End Property
' Get the value to replace the label
Public Property Let Lvalues (ByVal Values)
Strlvalues=values
End Property
'===========================================
' Class method
'===========================================
' Check template settings and whether there are
Private Function Check ()
If strtemp= "" Then
check= "<span style= ' color:red; ' > Error: Template file storage location not set! </span> "
Else
If FSO. FileExists (strtemp) =false Then
check= "<span style= ' color:red; ' > Error: The specified template does not exist! </span> "
Else
Check=true
End If
End If
End Function
' Read Template page
Public Sub readtemp ()
If Check () <>true Then
Response.Write Check ()
Response.End ()
Else
Set Getdatas=fso. OpenTextFile (Server.MapPath (strtemp))
Filedata=getdatas.readall
Getdatas.close
Set getdata=nothing
End If
End Sub
' Replace content
Public Function Rep ()
If strlabel= "" Then
Response.Write "<span style= ' color:red; ' > Error: No label is set to replace! </span> "
Response.End ()
End If
If strlvalues= "" Then
Response.Write "<span style= ' color:red; ' > Error: No replacement label data was set! </span> "
Response.End ()
End If
Filedata=replace (filedata,strlabel,strlvalues)
End Function
' Output
Public Sub Echo ()
Response.Write Filedata
End Sub
' Generate a static page
Public Sub gethtml ()
If strhtmlname= "" Then
Response.Write "<span style= ' color:red; ' > Error: The build HTML file storage location and file name are not set! </span> "
Response.End ()
End If
Set Htmlwrite=fso. CreateTextFile (Server.MapPath (Strhtmlname), true)
' Write page content
Htmlwrite. WriteLine Filedata
Htmlwrite. Close
Set htmlwrite=nothing
End Sub
End Class
%>
Usage examples:
Index.asp
Copy Code code as follows:
<!--#include file= "awa_temp. Class.asp "-->
<%
Set awa=new Awatemp
With AWA
. temp= "Temp.tpl"
. Readtemp
. Label= "{TL1}"
. lvalues= "Egg aches"
. Rep
. Echo
'. Htmlname= "Aa/index.html"
'. Gethtml
End With
Set awa=nothing
%>
Mould Plate
TEMP.TPL:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv=" Content-type " Content= "text/html; charset=gb2312 "/>
<title> Untitled document </title>
<body>
<table Width= "border=" 1 ">
<tr>
<td>{tl1}</td>
<td>{tl2}</td>
<td >{tl3}</td>
</tr>
<tr>
<td> </td>
<td> </td> ;
<td> </td>
</tr>
<tr>
<td> </td>
<td> ;</td>
<td> </td>
</tr>
</table>
</body>