Introduction to parameter transfer of ASP template Technology

Source: Internet
Author: User

In content system development, content and form separation are involved, that is, the process of replacing custom page templates with relevant content. This is essentially different from many content management systems on the entire site. There are many content management systems, many of which are used by users, because pages cannot be customized, and users who do not know programming cannot modify them. I guess there is no future for websites that just fill in a few parameters. Because everyone is like a person, and everyone will fill in those parameters.

For example, if you look at the following sites, you will think they are a setProgram?
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, designing different templates to get the page display, you will find that this system is superior and benign.

Of course, due to the high-end nature of this system, it is currently unavailable to common users, so I developed my own content management system, kiss content management system.

To give users a template system, we must first have a simple and easy-to-understand marking system. Let's take a look at the followingCodeTo see if it is easy to understand:
<Tag: loop channelid = "1" pagesize = "10" Title = "20" type = "new" column = "1">

People with a little HTML experience will know that this is the loop mark in a template tag, because this is the most commonly used. You can refer to the homepage of our website, to list 10 documents, you only need to write such a mark. Does this make it easy for programmers to design their own pages?

Parameter description:
Channelid is the ID of a column in the database
Pagesize indicates how many documents are listed.
Title indicates the title length.
Type is the list column type. Here we set "new" to the latest document.
Column indicates the number of columns displayed.

The above introduction is intended for people who do not know programming or content systems, and advertise my content management system. What I want to say is, the template module of the blue ideal site's content management system is much more powerful than mine.

The next step is the programmer's turn. You don't have to look at it.
So how can we read their values?
The following function is used to parse the content of all templates.

Copy code The Code is as follows: '[function] custom template tag
Function processcustomtags (byval scontent)
Dim objregex, match, matches
'Create a regular expression
Set objregex = new Regexp
'Search content
Objregex. pattern = "<Tag:. */>"
'Case insensitive
Objregex. ignorecase = true
'Global Lookup
Objregex. Global = true
'Run the search against the content string we 've been passed
Set matches = objregex. Execute (scontent)
'Found loop 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 object
Set matches = nothing
Set objregex = nothing
'Return Value
Processcustomtags = scontent
End Function

In the above Code, regular expressions are used. If you are not familiar with the regular expressions, please refer to the relevant materials and we will not detail them here.

How can we retrieve the parameter value? It is also a function: Code copy box

Copy code The Code is as follows: '[function] retrieves the parameter name of the template tag
'Example: <Tag: loop channelid = "1" pagesize = "10" Title = "20" type = "new" column = "1">
Function getattribute (byval strattritag, byval strtag)
Dim objregex, matches
'Create a regular expression
Set objregex = new Regexp
'The attribute name followed by double quotes etc)
Objregex. pattern = lcase (strattriase) & "=" "[0-9a-za-z] *"
'Case insensitive
Objregex. ignorecase = true
'Global Lookup
Objregex. Global = true
'Execute the search
Set matches = objregex. Execute (strtag)
'If a match exists, the return value is returned. Otherwise, the return value is null.
If matches. Count> 0 then
Getattribute = Split (matches (0). value, ") (1)
Else
Getattribute = ""
End if
'Destroy object
Set matches = nothing
Set objregex = nothing
End Function

Okay. How can I parse the content like <tagloop:> above?
The following is a function:

Copy code The Code is as follows: '[function] parses and replaces the corresponding template TAG content
Function parsetag (byval strtag)
Dim arrresult, classname, arrattributes, stemp, I, objclass
'Exit the function if the tag is empty.
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,
'Retrieve the name of the class
Classname = Split (arrresult (1), "") (0)
'Use a select case statement to work out which class we're dealing
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)
'Deststroy our class Object
Set objclass = nothing
End select
End Function

The above loop is a class and will not be detailed here. Because I haven't spoken for a long time, so I'm not used to it.
Conclusion: Through the above functions, you can quickly compile the relevant template program. Hope to 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.