In content system development, it involves the process of separating content and form, that is, the process of customizing page templates based on users and then replacing them with relevant content. This is fundamentally different from many whole-site content management systems outside. There are many content management systems that look the same no matter how many people use them, because the pages cannot be customized and users who do not know programming cannot modify them. I don't think a website like that, which only fills in a few parameters and comes out, has much future. Because everyone looks the same and everyone knows how to fill in those parameters.
For example, if you look at the following sites, would you think they are a set of programs?
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, and the relevant webmasters only design different templates to get the page display, you will find the excellence of this system.
Of course, due to the high-end nature of this system, it is currently not available to ordinary users, so I developed my own content management system, kiss content management system.
To provide users with a template system, first of all, there must be a simple and easy-to-understand marking system. Take a look at the following code to see if it is easy to understand:
<tag:loop channelid=1 pagesize=10 />channelid is the ID of a column in the database
pagesize is how many documents to list
title is the length of the title
type is a list column type, and NEW here is set to the latest document
column is how many columns to display
The above introduction is to popularize it for people who don’t know programming or don’t understand the content system, and to advertise my content management system, and what I want to say is, the content management system template module used by the Blue Ideal site, Much stronger than mine.
Now it's the programmer's turn, others don't need to look down.
So how to read their values?
The following function is the last one and is used to parse the contents of all templates
Copy the code as follows:'[Function] Custom template tag
Function ProcessCustomTags(ByVal sContent)
Dim objRegEx, Match, Matches
'Create regular expression
Set objRegEx = New RegExp
'Find content
objRegEx.Pattern = <tag:.*/>
' Ignore case
objRegEx.IgnoreCase = True
'Global search
objRegEx.Global = True
'Run the search against the content string we've been passed
Set Matches = objRegEx.Execute(sContent)
'Loop through the found matches
For Each Match in Matches
'Replace each match with the appropriate HTML from our 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
uses regular expressions in the above code. If you don't know much about it, please refer to the relevant information. I won't go into details here.
So how to get the parameter value, it is also a function:
copy the code in the code copy box as follows:'[Function] Get the parameter name of the template tag
' such as: <tag:loop channelid=1 pagesize=10 />function GetAttribute(ByVal strAttribute, ByVal strTag)
Dim objRegEx, Matches
'Create a regular expression
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 search
objRegEx.Global = True
'Execute search
Set Matches = objRegEx.Execute(strTag)
'If there is a match Then return a value, otherwise return 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 parse the content like <tagloop:> above?
The following is a function:
copy the code as follows:'[Function] Parse and replace the corresponding template tag content
function ParseTag(ByVal strTag)
dim arrResult, ClassName, arrAttributes, sTemp, i, objClass
'If the tag 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
The loop above
the function
is a class, so I won’t go into details here.Because I haven’t spoken for a long time and I’m not used to it, haha.
Conclusion, through the above function, you can quickly write related template programs. Hope it helps.