Code Separation methods for foreigners

Source: Internet
Author: User
Tags date exit integer tagname
Code Separation index.asp
-----------------------------------------------------------------------
<!--#include file= "templateclass.asp"-->
<%
' This is the code used to load and display the template.
' How to clean it '!!! :)
Sub Go ()
Dim otemplate

Set otemplate = new template

With Otemplate
. Usetemplate ("Message.tpl")
. Tag ("date") = Date ()
. Tag ("self") = "<div style= ' background: #dddddd ' >" &. GetTemplate ("Message.tpl", True) & "</div>"
. Tag ("aspcode") =. GetTemplate ("index.asp", false)
. Tag ("howtouse") =. GetTemplate ("Howtouse.tpl", false)
. Display ()
End With

Set otemplate = Nothing
End Sub
Go ()
%>

Templateclass.asp
------------------------------------------------------------------------
<%
' This is the template object. It allows the creation, reading
' and editing of templates on the server.
' CREATED by:christopher Brown-floyd
' Date:november 3, 1999
Class template

' This variable stores the template
Private MyTemplate ' As String

' This method gets a template from the server and returns
' The whole file as a string.
Public Function GetTemplate (pathfilename,encodetohtml) ' As String
Dim oFSO ' As Object
Dim Otemplate ' As Object
Dim Temptemplate ' As String

' Open type for the template (read-only)
Const ForReading = 1,boolcreatefile = False

If IsNull (encodetohtml) or encodetohtml = "" or encodetohtml = False Then
Encodetohtml = False
Else
Encodetohtml = True
End If


On Error Resume Next
' Create FileSystemObject
Set oFSO = Server.CreateObject ("Scripting.FileSystemObject")

' Create Template Object
Set otemplate = Ofso.opentextfile (Server.MapPath (pathfilename), forreading,boolcreatefile)
If Err <> 0 Then
Err.Clear
Exit function
End If
' Get the whole file as a string
Temptemplate = Otemplate.readall

' Encode template to HTML?
If Encodetohtml Then
GetTemplate = tohtml (temptemplate)
Else
GetTemplate = Temptemplate
End If

' Close the template
Otemplate.close

' Free ' of the server resources
Set otemplate = Nothing

Set oFSO = Nothing
End Function


' This procedure gets and stores a template
Public Sub Usetemplate (pathfilename)
Thistemplate = GetTemplate (pathfilename,false)
End Sub


' This property replaces tags with the user ' s template
Public Property Let tag (tagname,userstring)
Dim ld, RD ' As String
Dim Temptag ' As String
Dim Tagstart, Tagend ' As Integer

LD = "<!--"
RD = "-->"
Tagstart = 1

Do While Tagstart > 0 and Tagstart < Len (thistemplate)
Tagstart = InStr (TAGSTART,THISTEMPLATE,LD)
If Tagstart > 0 Then
Tagend = InStr (TAGSTART,THISTEMPLATE,RD)
If Tagend > (Tagstart + 3) Then
Temptag = Mid (Thistemplate,tagstart + 4,tagend-(tagstart+4))
if (Trim (temptag) = tagname) or (Temptag = tagname) Then
If IsNull (userstring) Then
Thistemplate = replace (thistemplate,ld & temptag & Rd, "")
Else
Thistemplate = replace (Thistemplate,ld & Temptag & rd,userstring)
End If
Exit Do
Else
Tagstart = Tagstart + 4
End If
End If
End If
Loop
End Property


Public Sub Removetags ()
Dim ld, RD ' As String
Dim Temptag ' As String
Dim Tagstart, Tagend ' As Integer

LD = "<!--"
RD = "-->"
Tagstart = 1

Do While Tagstart > 0 and Tagstart < Len (thistemplate)
Tagstart = InStr (TAGSTART,THISTEMPLATE,LD)
If Tagstart > 0 Then
Tagend = InStr (TAGSTART,THISTEMPLATE,RD)
If Tagend > (Tagstart + 3) Then
Temptag = Mid (Thistemplate,tagstart + 4,tagend-(tagstart+4))
Thistemplate = replace (thistemplate,ld & temptag & Rd, "")
Tagstart = Tagend
End If
End If
Loop
End Sub


' This property allows the "user to assign" current template
Public Property Let Thistemplate (template_as_string)
If VarType (template_as_string) = Vbstring _
or VarType (template_as_string) = Vbnull Then
MyTemplate = template_as_string
End If
End Property



Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.