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
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
End Function
' Variable substitution process
Function Of_replace (ByVal ps_handle)
if (not Of_loadfile (ps_handle)) Then
Ls_error= "of_replace:unable to load" +ps_handle
Response.Write (Ls_error)
Of_replace=false
Exit function
End If
For I=li_minindex to Li_maxindex
Set regEx = New RegExp
Regex.pattern = Gs_keyvars (i)
Regex.ignorecase = True
Ls_str = Regex.Replace (Ls_str, Gs_vars (i))
Next
Of_replace=ls_str
End Function
' Get storage variables
Function Of_getvar (ByVal ps_keyname)
Li_keyindex=of_getindex (Gs_keys,ps_keyname)
if (li_keyindex= "no") then
Of_getvar= ""
Else
Ls_varname=gs_vars (Li_keyindex)
Of_getvar=ls_varname
End If
End Function
' Find the index value of the corresponding string in the array
Function Of_getindex (ByVal ps_array,byval Ps_handle)
Li_minindex=lbound (Ps_array)
Li_maxindex=ubound (Ps_array)
li_index= "No"
For I=li_minindex to Li_maxindex
if (Ps_array (i) =ps_handle) then
Li_index=i
Exit For
End If
Next
Of_getindex=li_index
End Function
' Analyze variables
Function Of_parse (ByVal ps_target,byval Ps_handle,byval Ps_append)
ls_string = Of_replace (ps_handle)
If Ps_append=true Then
ls_org = Of_getvar (ps_target) & ls_string
' If pi_time=2 then
' Response.Write (ls_string)
' Exit function
' End If
Call Of_setvar (ps_target,ls_org)
Else
Call Of_setvar (ps_target,ls_string)
End If
End Function
Function Of_print (ByVal ps_keyname)
Li_keyindex=of_getindex (Gs_keys,ps_keyname)
Ls_varstring=gs_vars (Li_keyindex)
Set regEx = New RegExp
Regex.pattern = "{[^ \t\r\n}]+}"
Regex.ignorecase = True
ls_varstring = Regex.Replace (ls_varstring, "")
Of_print=ls_varstring
End Function
End Class
%>
Call Page:
<%
Dim c_html
Set c_html = new Template
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.