Relatively good ASP template Primer Ultimate Explanation (Web Development ASP mode) _ Application Skills
Source: Internet
Author: User
Author: Sun Li email:17bizat126.com
Written in: 2006/3/5
Copyright NOTICE: You can reprint, reprint, please be sure to hyperlink form to indicate the original source of the article and author information and this statement
Http://sunli.cnblogs.com/archive/2006/03/05/343095.html
Tags: ASP templates
Abstract: 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.
Absrtact: A new ASP template engine is introduced to realize the separation of code (logic) layer and HTML (performance) layer. This template implementation avoids the general ASP template loading template file (load
components) and replace the wasted resources, the implementation of a compiled template engine, improve 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-->
234<title>{$title}</title>
56<body>
7{$body}
8</body>
91<!--template.asp-->
2<%
3templatecode=load ("template.html") ' Custom function, mount 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.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 exists the problem is that the template needs to be used every time to parse, 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 3 4 <title><%=title%></title>
5 6 <body>
7 <!--<%
8 ' If logic control, of course, here for the For,while cycle is also handled, is not it very simple,
9 ' Logic HTML annotation, under the DW (Dreamweaver) should not be the logical control of the ASP placeholder distortion, for other variables will display an ASP tag, easy to modify
Ten IF catalog= "Music" Then
One%>-->
<%=music%>
<!--<%Else%>-->
<%=book%>
<!--<%end if%>-->
</body>
1 <!--template.asp-->
2 <%
3 title= "ASP template engine Terminator"
4 catalog= "Music"
5 music= "Music"
6 book= "book"
7%>
8 <!--#include file= "template.html"--> idea: 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 is the same), in the template file with <%% > Direct control of variable display and logic control, not displayed logical control character with HTML annotation <!----> comment out, of course, not annotation is also OK. This is the last "<!--#include file= in ASP file" Template.html "-->" on the implementation of the template and ASP file combination, to achieve the code and performance layer of separation, there is no use of ASP to go to the load template, and then replace, waste unnecessary ASP resources. All 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.
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.