In the development of the content system, the process of separating the content from the form, that is, the process of replacing the relevant content according to the user's custom page template. This and many outside the whole station of the content management system, there is a fundamental difference. There are a lot of content management system, how many people use, is a look, because the page can not be customized, do not understand programming users can not modify. Like that, just fill out a few parameters to come out of the site, I guess there is no future. Because everyone is a look, everyone will fill those parameters.
For example, if you look at the following sites, do you think they are a set of procedures?
Www.blueidea.com
Http://pages.blueidea.com
Http://digi.blueidea.com
Http://dsp.blueidea.com
Http://www.dcshooter.com
If I tell you that they are all a program, just by the relevant webmaster, design a different template to get the page displayed, you will find that this system is excellent.
Of course, due to the high-end nature of the system, the current ordinary users can not use, so I developed my own content management system Kiss Content management system.
And to give users a template system, first of all, is to have a simple and easy to understand the marking system. Let's look at the following code to see if it's easy to understand:
<tag:loop channelid= "1" pagesize= "title=" type= "NEW" column= "1" >
People with a bit of HTML experience know that this is a circular marker in a template tag, because this is the most commonly used, you see the homepage of our website, List 10 documents also just need to write one such mark to complete, this is not to let the people who do not understand programming, also very easy to make their own design page out?
Parameter description:
Channelid is the ID of a column in the database
PageSize How many documents to enumerate
Title is the length of the caption
Type is a list column type, where the "new" we set as the most recent document
Column to display several columns
The above introduction is to not programming, or to do not understand the content system of the people do a popular, and to my content management system to advertise, and I want to say that the blue ideal site for the Content Management System template module, much more powerful than my.
The next turn is for programmers, and the rest of the people don't have to look down.
So how do you read their values?
The following function is the last one to parse the contents of all templates
Copy Code code as follows:
' Feature ' Custom template label
Function processcustomtags (ByVal scontent)
Dim Objregex, Match, Matches
' Establish regular expressions
Set Objregex = New RegExp
' Find content
Objregex.pattern = "<tag:.*/>"
' Ignore case
Objregex.ignorecase = True
' Global Lookup
Objregex.global = True
' Run the ' search against the content string we ' ve been passed
Set matches = Objregex.execute (scontent)
' Loops have found a match
For the Match in matches
' Replace each match with the appropriate HTML Parsetag function
Scontent = Replace (scontent, Match.value, Parsetag (Match.value))
Next
' Destroy the object
Set matches = Nothing
Set Objregex = Nothing
' Return value
Processcustomtags = Scontent
End Function
In the above code, the regular expression is used, if you do not know it very well, please refer to the relevant information, here is not detailed.
So how do I get the value of a parameter and it's also a function: Code copy Box
Copy Code code as follows:
' Feature ' gets the parameter name of the template label
' such as: <tag:loop channelid= "1" pagesize= "title=" type= "NEW" column= "1" >
function getattribute (ByVal strattribute, ByVal strtag)
Dim Objregex, Matches
' Establish regular expressions
Set Objregex = New RegExp
' Find content (the attribute name followed by double quotes etc)
Objregex.pattern = LCase (strattribute) & "=" [0-9a-za-z]*] ""
' Ignore case
Objregex.ignorecase = True
' Global Lookup
Objregex.global = True
' Perform a search
Set matches = Objregex.execute (Strtag)
' Returns a value if there is a match, otherwise it returns a null value
If Matches.count > 0 Then
GetAttribute = Split (Matches (0). Value, "" "" ") (1)
Else
GetAttribute = ""
End If
' Destroy the object
Set matches = Nothing
Set Objregex = Nothing
End Function
OK, then how to resolve like above <tagloop:> content?
Here's a function:
Copy Code code as follows:
' Feature ' resolves and replaces the corresponding template label contents
function Parsetag (ByVal strtag)
Dim Arrresult, ClassName, Arrattributes, Stemp, I, objclass
' If the label is empty, exit the function
If Len (strtag) = 0 Then Exit function
' Split the match ' on the colon character (:)
Arrresult = Split (Strtag, ":")
' Split the second item of the ' resulting array on the "space character," to
' Retrieve ' The name of the class
ClassName = Split (Arrresult (1), "") (0)
' Use a Select Case statement to work out which class we ' re dealing with
' and therefore which properties to populate etc
Select Case UCase (ClassName)
' It ' s a loop class, so instantiate one and get It ' s properties
Case "LOOP"
Set objclass = new Loop_class
LOOP. Channelid= getattribute ("Channelid", Strtag)
LOOP. Pagesize= getattribute ("Pagesize", Strtag)
Loop.title = getattribute ("title", Strtag)
Loop.type = getattribute ("type", Strtag)
Parsetag = Loop.column (getattribute ("column", Strtag), True)
' Destroy our Class object
Set objclass = Nothing
End Select
End Function
The loop above is a class and is no longer detailed here. Because for a long time did not speak, not very accustomed to, hehe.
conclusion, through the above function, you can quickly write the relevant template program. I hope it will help you.