Templates used in PHP, used phplib used, no he felt very uncomfortable
The internet to find no one to write, their own wrote a, ASP level is not high, I hope
Can have the master to change.
<%
' ====================================
' Name:template Class
' Purpose:parse and Output HTML page
' Date:10.2002
' Author:pig
' Email:pigzjq@sina.com
' phone:13910320759
' ====================================
Class Template
Dim gs_root
Dim Gs_handle ()
Dim Gs_file ()
Dim Gs_keys ()
Dim Gs_keyvars ()
Dim Gs_vars ()
' Constructor
Private Sub template_initialize ()
Call Of_setroot (".")
' Call Of_redimvar ()
End Sub
function Of_redimvar ()
ReDim Gs_handle (0)
ReDim Gs_file (0)
ReDim Gs_keys (0)
ReDim Gs_keyvars (0)
ReDim Gs_vars (0)
End Function
' Set template Store path
function Of_setroot (ByVal ps_root)
If Ps_root <> "" Then
Gs_root = Ps_root
End If
End Function
' Set file name function
function Of_setfile (byVal ps_filehandle,byval ps_filename)
If Ps_filename <> "" Then
Li_maxnum=ubound (Gs_handle)
Gs_handle (li_maxnum) = Ps_filehandle
Gs_file (li_maxnum) = gs_root+ "/" +ps_filename
Li_maxnum=li_maxnum+1
ReDim Preserve Gs_handle (Li_maxnum)
ReDim Preserve Gs_file (Li_maxnum)
End If
End Function
' Set the parameter variables to replace
function Of_setvar (byVal ps_key,byval Ps_var)
If Ps_key <> "" and Ps_var <> "" Then
Li_keyindex=of_getindex (Gs_keys,ps_key)
If li_keyindex= "No" then
Li_maxnum=ubound (Gs_keys)
Gs_keys (Li_maxnum) =ps_key
Gs_keyvars (Li_maxnum) = "\{" & Ps_key & "\}"
Gs_vars (Li_maxnum) =ps_var
Li_maxnum=li_maxnum+1
ReDim Preserve Gs_keys (Li_maxnum)
ReDim Preserve Gs_keyvars (Li_maxnum)
ReDim Preserve Gs_vars (Li_maxnum)
Else
Gs_keys (Li_keyindex) =ps_key
Gs_keyvars (Li_keyindex) = "\{" & Ps_key & "\}"
Gs_vars (Li_keyindex) =ps_var
End If
End If
End Function
' Define overloaded text blocks
function Of_setblock (byVal ps_parent,byval ps_handle,byval ps_name)
if (not Of_loadfile (ps_parent)) Then
Ls_error= "Of_loadfile Unable to load" +ps_parent
Response.Write (Ls_error)
Of_setblock=false
Exit function
End If
If Ps_name= "" Then
Ps_name=ps_handle
End If
Ls_string=of_getvar (ps_parent)
Ls_pattern = "<!--\s*begin" &ps_handle& "\s*--> (. *) <!--\s*end" &ps_handle& "\s*-->"
Set regEx = New RegExp
Regex.pattern = "\ n"
Regex.ignorecase = False
Regex.global = True
ls_string = Regex.Replace (ls_string, "")
Regex.pattern = Ls_pattern
Regex.multiline = True
Regex.global = False
Set matches = Regex.execute (ls_string)
ls_string = Regex.Replace (ls_string, "{" &ps_name& "}")
For the Match in matches
Ls_value=match.value
Next
Regex.pattern = "<!--\s*begin" &ps_handle& "\s*-->"
Regex.ignorecase = False
Regex.global = True
Ls_value = Regex.Replace (Ls_value, "")
Regex.pattern = "<!--\s*end" &ps_handle& "\s*-->"
Regex.ignorecase = False
Regex.global = True
Ls_value = Regex.Replace (Ls_value, "")
Call Of_setvar (Ps_handle,ls_value)
Call Of_setvar (ps_parent,ls_string)
End Function
' Load variable content
function Of_loadfile (ByVal ps_handle)
Li_keyindex=of_getindex (Gs_keys,ps_handle)
If Li_keyindex = "No" Then
Li_fileindex=of_getindex (Gs_handle,ps_handle)
If Li_fileindex = "No" Then
Ls_error= "LoadFile:" +ps_handle+ "is not a valid handle."
Response.Write (Ls_error)
Of_loadfile=false
Exit function
End If
Ls_filename=gs_file (Li_fileindex)
Ls_filename=server.mappath (Ls_filename)
Set myfileobject=server.createobject ("Scripting.FileSystemObject")
Li_exist=myfileobject.fileexists (Ls_filename)
If Li_exist Then
Set Mytextfile=myfileobject.opentextfile (Ls_filename)
Ls_file=mytextfile.readall ()
Mytextfile.close
Call Of_setvar (Ps_handle,ls_file)
Else
Ls_error= "LoadFile:" +ls_filename+ "is not a valid file or path."
Response.Write (Ls_error)
Of_loadfile=false
Exit function
End If
End If
Of_loadfile=true