SoFunction
Updated on 2025-03-10

A good asp template introduction ultimate explanation (WEB development ASP model)

Author: Sun Li Email:
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.
/archive/2006/03/05/
Keywords: ASP template
Abstract: Explain a brand new ASP template engine to separate the code (logical) layer and HTML (presentation) layer. This template implementation method avoids the general ASP template loading template files (loading components) and replacing waste resources, implements a compiled template engine, and improves 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 various applications have increasingly required 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<!---->
2<html>
3<head>
4<title>{$title}</title>
5</head>
6<body>
7{$body}
8</body>
9</html>
1<!---->
2<%
3TemplateCode=Load("")' 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
 TemplateCode
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, and 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 from compiled templates, 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 <!---->
 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?
9 'Use html comments on the logic, and under DW (Dreamweaver), the logic-controlled asp placeholder will not be deformed. For other variables, an asp mark will be displayed for easy modification.
10 IF Catalog="music" Then
11 %>-->
12 <%=music%>
13 <!--<%Else%>-->
14 <%=book%>
15 <!--<%End If%>-->
16 </body>
17 </html>
1 <!---->
2 <%
3 title="asp template engine terminator"
4 Catalog="music"
5 music="Music"
6 book="book"
7 %>
8 <!--#include file=""-->Idea: Asp files perform regular logical processing and calculations, and do not care about the display layer. Of course, the variables that need to be displayed need to be combined with the display layer (the same is true for PHP). In the template file, use <%%> to directly control the display and logical control of variables. The logical control characters that are not displayed are commented out with the html comment. Of course, it is also possible to not comment. In this way, the combination of templates and ASP files is achieved at the end of the ASP file, and the separation of code and presentation layer is achieved. There is no ASP loading templates and then replacing them, wasting unnecessary ASP resources. All these processing is omitted. You will find it easier to write ASP files because you no longer need to control the behavior of replacement, logical display. Direct execution in ASP is definitely faster and more stable than replacement. Moreover, when loading templates, you must also load a component.
Having written this, you may understand the essence of this type of template. It is just a design pattern, not a template engine that uses template classes to process it.