Talking about the parameter transfer of ASP template technology

Source: Internet
Author: User
Tags exit case statement copy end expression regular expression split
Template

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://wuyi.digichina.net
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. Everyone can visit http://aston.blueidea.com

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

Code Copy Box
' Feature ' custom template tag function processcustomtags (ByVal scontent) Dim Objregex, Match, matches ' set up regular expression set OBJR Egex = 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 Mat Ches = Objregex.execute (scontent) ' Loop found match for each match in matches ' Replace each match with the AP Propriate HTML from our parsetag function scontent = Replace (scontent, Match.value, Parsetag (Match.value)) Next ' Destroy object Set matches = Nothing Set Objregex = Nothing ' return value Processcustomtags = Sconte Ntend Function
[Ctrl + a All select and copy]

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 you get the value of a parameter, and also a function:
Code Copy Box
' function ' 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 expression set Objregex = New RegExp ' Find content (the attribute name followed by double Qu OTEs etc) Objregex.pattern = lCase (strattribute) & "=" [0-9a-za-z]*] "" ' Ignore case Objregex.ignoreca SE = True ' global lookup Objregex.global = True ' performs search Set matches = objregex.execute (strtag) ' If there is a match Returns a value that otherwise returns null if Matches.count > 0 Then getattribute = Split (Matches (0). Value, "" "" "" "(1) Else getattribute =" "" End If "destroy object Set matches = Nothing Set Objregex = NothingEnd function
[Ctrl + a All select and copy]

OK, then how to resolve like above <tagloop:> content?
Here's a function:

Code Copy Box
' Feature ' resolves and replaces the corresponding template label content 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 (:) arrres Ult = Split (Strtag, ":") ' Split the second item of the resulting array on the spaces character, to ' retrieve T He name of the class ClassName = Split (Arrresult (1), "") (0) ' Use a Select Case statement to work out whic H 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) ' De Stroy our class object Set objclass = no end SelectEnd function
[Ctrl + a All select and copy]

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.



Related Article

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.