Author: Sun Li Email:17bizAT126.com
Written on: 2006/3/5
Copyright Statement: You can reprint it at will. When reprinting, please be sure to indicate the original source of the article, the author information and this statement in the form of a hyperlink.
http://sunli.cnblogs.com/archive/2006/03/05/343095.html
Keywords: ASP template
Abstract: A new ASP template engine is described, which realizes the separation of the code (logical) layer and the HTML (presentation) layer. This template implementation method avoids the wasteful resources of general ASP templates loading template files (loading components) and replacing wasteful resources, and realizes a compiled template engine to improve the execution speed and stability of the program.
Abstract: Explain a brand new ASP template engine to separate the code (logical) layer and the HTML (presentation) layer. This template implementation method avoids the general ASP template loading template files (loading)
Components) and replace wasted resources to realize a compiled template engine, and improve program execution speed and stability.
content:
Currently, WEB development has become very popular because of various applications, which require increasingly separation of the presentation layer and the logic layer. ASP and HTML are sandwiched together and the program will become difficult to maintain and have poor readability. In the PHP field, template engines are already very common, such as phplib, SMARTY, etc. There are alternative methods, and there are also compilation methods (SMARTY), which all better realize the separation of logic and presentation layers. Due to the influence of PHP, in the ASP industry, some people use phplib and other methods to develop asp template classes. Since ASP's performance is not very powerful in character processing, it is affected in speed. Such templates are not widely used in the current situation. like:
1<!--template.html-->
2<html>
3<head>
4<title>{$title}</title>
5</head>
6<body>
7{$body}
8</body>
9</html>
1<!--Template.asp-->
2<%
3TemplateCode=Load("template.html")'Custom function, load template file to TemplateCode
4TemplateCode=Replace(TemplateCode,"{$title}","asp template engine terminator")'Replace template
5TemplateCode=Replace(TemplateCode,"{$body}","asp template engine terminator content")'Replace template
6Response.WriteTemplateCode
7%>The above example only shows the current idea of ASP templates. The ASP version of the CMS system has embedded logical control over the template. Although it can achieve the separation of logic and interface, the problem with this template is that the template needs to be parsed once every time with ASP. The program is equivalent to parsing twice. And when there is a lot of content to be replaced, the performance will be reduced. Moreover, the server needs to support a component (FSO, ADODB, XMLHTTP can be implemented).
Borrowing the compiled template, I introduced this idea in ASP. I proposed a template system with excellent functions and performance applied in ASP. The following is expressed in code:
1<!--template.html-->
2<html>
3<head>
4<title><%=title%></title>
5</head>
6<body>
7<!--<%
8'If logic control, of course, the same process for FOR and While loops here, do you think it is very simple?