ASP template engine terminator (ASP mode of Web development) _asp Foundation

Source: Internet
Author: User
Describes a new ASP template engine, implement the separation of the Code (logical) layer from the HTML (presentation) layer. This template implementation avoids the general ASP template loading template files (loading components) and replacing the wasted resources, realizing the compile-type template engine, improving the execution speed and stability of the program.

content:
At present, web development has become very popular, because a variety of applications, has been about to require the separation of the presentation layer and the logical layer. ASP and HTML folders together, the program will become difficult to maintain, and the readability is poor. In the field of PHP, template engines are already very common, such as Phplib,smarty, and so on. There are the use of replacement, but also the compiler (SMARTY), they are better to achieve the logical layer and the performance layer separation. Due to the influence of PHP, In the ASP industry, some people use the substitution method to develop ASP template class, because the ASP in character processing performance is not very strong, so in the speed is affected, such a template in the current application is not very wide. Such as:
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 : %
3 templatecode = Load ( "" template.html ) ' custom function, loading template file to Templatecode
4 Templatecode = Replace (Templatecode, " {$title} " , " asp template engine Terminator " ) ' replace template
5 templatecode = Replace (Templatecode, {$body} , ' asp template engine Terminator content ' ' ' replace template
6 response.write templatecode
7 % :
The above example is only a preliminary demonstration of the current ASP template idea, there is an ASP version of the CMS system has been embedded in the logic of the template control, although the logic and interface to achieve the separation, but the template is the problem is that the template needs to be used every time with ASP parsing, the program equivalent to two And when you want to replace a lot of content, it will degrade performance. And the load template requires that the server support a component (Fso,adodb,xmlhttp can be implemented).
Drawing on the compiled template, I introduced this idea in ASP. A template system with excellent function and performance in ASP is proposed. The following code indicates:
1<!--Template.html-->
2<Html>
3<Head>
4<Title><%=Title%></Title>
5</Head>
6<Body>
7<!--<%
8 ' If logic control, of course, is also handled here for the for,while  Loop, does it feel very simple,
 9  ' makes HTML comments on logic, in the DW (Dreamweaver will not distort the ASP placeholder for logical control, and an ASP tag will be displayed for other variables to make it easier to modify the
10  if catalog= "Music"  then
11  %>
12  <% = music %>
13  <!-- <%else%> 14 
<% = book %>
15  <!-- <%End If%>
16 , </ body ,
17  </ html

1 <! --template.asp-->
2 <%
3 Title="asp template engine Terminator "
4 Catalog="Music"
5 Music=" musical "
6 book =" Books "
7 %>
8 <! --#include file="template.html"-->
Thinking: ASP file for conventional logic processing, operation, without the tube display layer, of course, need to display the variable needs and display layer combination (PHP), in the template file with <%%> Direct control of variable display and logic control, not display logical control character with HTML annotation character <!- ---> Comment out, of course, not annotation is also possible. So in the end of the ASP file "<!--#include file=" template.html "-->" on the implementation of the template and ASP file, the separation of code and presentation layer, There is no ASP to go to the load template, and then replace, waste unnecessary ASP resources. All of these treatments are omitted. You will find it more convenient to write ASP files, because you no longer need to control the substitution in which the logical display of the behavior. Direct execution in an ASP is certainly faster and more stable than the replacement. Besides, you have to load a component when loading the template.
Writing here, you may understand the essence of this template, it is just a design pattern, not a template class to deal with the template engine.
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.