Friends who need the simplest template class of ASP Crazy template operation class can refer to it. File name: Awa_temp.Class.asp
Copy the code code as follows:
<%
'Crazy frog! Template operation class
'Author Crazy~frog! QQ:379969387 Welcome to communicate
'Version V1.0;
ClassAwaTemp
Public aa
Private FSO,StrTemp,FileData,GetDatas,StrHtmlName,htmlwrite,StrLabel,StrLValues
'============================================
'Constructor_Initialize FSO component
'============================================
Private Sub Class_Initialize()
Set FSO=Server.CreateObject(Scripting.FileSystemObject)
End Sub
'============================================
'Destructor_Destroy FSO component
'============================================
Private Sub Class_terminate()
Set FSO=nothing
End Sub
'============================================
'Class attribute
'============================================
'Version information
Public Property Get Version
Version=Crazy~frog! Template operation class! V1.0 version;
End Property
'Get the 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 tags
Public Property Let Label(ByVal Values)
StrLabel=Values
End Property
'Get the value that replaces the label
Public Property Let LValues(ByVal Values)
StrLValues=Values
End Property
'============================================
'Class method
'============================================
'Check template settings and whether they exist
Private Function Check()
If StrTemp= Then
Check=<span style='color:red;'>Error: The template file storage location is 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: The tag to be replaced is not set! </span>
Response.End()
End If
If StrLValues= Then
Response.Write <span style='color:red;'>Error: The data for the replacement tag is not set! </span>
Response.End()
End If
FileData=Replace(FileData,StrLabel,StrLValues)
End Function
'Output
Public Sub Echo()
Response.Write FileData
End Sub
'Generate static page
Public Sub GetHtml()
If StrHtmlName= Then
Response.Write <span style='color:red;'>Error: The storage location and file name of the generated Html file are not set! </span>
Response.End()
End If
Set htmlwrite=FSO.CreateTextFile(Server.MapPath(StrHtmlName),true)
'Write web page content
htmlwrite.WriteLine FileData
htmlwrite.Close
sethtmlwrite=Nothing
End Sub
End Class
%>
Usage examples:
index.asp
Copy the code code as follows:
<!--#include file=Awa_temp.Class.asp-->
<%
Set awa=New AwaTemp
With awa
.Temp=temp.tpl
.ReadTemp
.Label={tl1}
.LValues=It hurts
.Rep
.Echo
'.HtmlName=aa/index.html
'.GetHtml
End With
Set awa=nothing
%>
stencil
temp.tpl:
Copy the code code as follows:
<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv=Content-Type content=text/html; charset=gb2312 />
<title>Untitled Document</title>
</head>
<body>
<table width=200 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>
</html>