ASP generic template classes.
Suitable for templates with fewer loops. Internal loops are not implemented, and regular expressions are used, which is a waste of resources and time, if you need to use this article.
Characteristics
can set private cache or public cache to improve efficiency
Free to choose to use the Stream component or the FSO component
Support for custom file encoding
To save a file
Property
Name
Text, the template name, used primarily to differentiate different templates when using common caching.
Format
Text, file encoding type, can set value.
Object
Text, using components, you can set values:
Stream
Fso
Publiccache
Boolean value, using the public cache, the template file is saved to the Application object when it is opened, and other objects referencing the template class set the same name value and also open the common cache to read from the cache. (Load method)
Privatecache
Boolean value, using private caching, the template file will be saved to an object internal variable when opened, and the same object referencing this template class can be read. (Load method)
Direction
Text, the directory where the template file is located, without either a slash or a backslash, such as: Template/default
File
text, template filename, without a slash or backslash, such as: default.html
Savedirection
Text, save the file in the directory, no forward or backward slash or backslash, such as: Html/default
SaveFile
Text, save file name, no trailing slash or backslash, such as: default.html
Object
Code
Text, current text, replacing this object when using the Setvar method, overloading the template to this object when using the Load method
Storage
Text, saved text, saving text in a code object to the beginning or end of this object when using the Savefront or Savelast method, and can be used to get all the code after the loop
Method
ClearCache
Clear public and private caches (force templates to be overloaded from files)
Clearpubliccache
Clear public cache
Clearprivatecache
Clear Private Cache
Clearcode
Clear the Code object
Clearstorage
Clear Storage Object
Savefront
Saves the text in the current code object to the beginning of the storage object
Savelast
Saves the text in the current code object to the end of the storage object
Savecode
Saves text in the current code object to a file
Savestorage
Saves text in the current storage object to a file
SetVar
Replaces text in the current code object
Argument: text that needs to be replaced, text to replace
Load
Load the template file into the code object, load from the private cache when the private cache is turned on and on, and when it is on the public cache, load from the public cache, and load from the file without caching
Internal variables
Ccstrpath
Default root directory
Ccstrcookiename
Default Application object name prefix
Code
Class ccclstemplate
Private Ccstrcode,ccstrstorage
Private Ccstrcachecode
Private Ccblnpubliccache,ccblnprivatecache
Private Ccstrname,ccstrcookiename
Private Ccstrdirection,ccstrsavedirection,ccstrfile,ccstrsavefile,ccstrpath
Private Ccobjstream,ccobjfso,ccstrformat,ccintobject,ccobjtext,ccintformat
Private Sub Class_Initialize
Ccstrname = "Default" defaults to name
Ccblnpubliccache = False
Ccblnprivatecache = False
Ccstrfile = "Cache.html"
Ccstrsavefile = "Save_cache.html"
Ccstrcookiename = "Ccclass_template" ' Application object name prefix
Ccstrformat = "UTF-8" ' utf-8| ascii| gb2312| BIG5
Ccintformat =-1
Ccintobject = 1 ' default read/Save Template Component 1:adodb. Stream 2:fso
Ccstrpath = Server.MapPath ("./") & "' Default root Path
End Sub
Public Property Let Name (ccstrname_in)
Ccstrname = LCase (Trim (ccstrname_in))
End Property
Public Property Let Format (ccstrformat_in)
Ccstrformat = ccstrformat_in
If InStr (Trim (ccstrformat_in), "UTF") > 0 Then
Ccintformat =-1
Else
Ccintformat = 0
End If
End Property
Public Property Let Object (ccstrobject_in)
ccstrobject_in = LCase (Trim (ccstrobject_in))
If InStr (ccstrobject_in, "FSO") > 0 Then
Ccintobject = 2
Else
Ccintobject = 1
End If
End Property
Public Property Let Publiccache (ccblnpubliccache_in)
If ccblnpubliccache_in = True Then
Ccblnpubliccache = True
Else
Ccblnpubliccache = False
End If
End Property
Public Property Let Privatecache (ccblnprivatecache_in)
If ccblnprivatecache_in = True Then
Ccblnprivatecache = True
Else
Ccblnprivatecache = False
End If
End Property
Public Property Let Direction (ccstrdirection_in)
Ccstrdirection = ccstrdirection_in
End Property
Public Property Let File (ccstrfile_in)
If ccstrfile_in <> "" Then