Describe a brand new ASP template engine to implement Code (Logic) layer and HTML (Presentation) layer separation. this template implementation method avoids the waste of resources such as loading template files (loading components) and replacing them with ASP templates, implements a compiled template engine, and improves Program Execution speed and stability.
Content:
At present, web development has become very popular, because of various applications, it has been about to require the separation of the presentation layer and the logic layer. adding ASP and HTML together will make it difficult to maintain and make it less readable. In the PHP field, the template engine is already very common, such as phplib, smarty, and so on. there are replacement methods and compilation methods (smarty), which are good for separating the logical layer and the presentation layer. due to the influence of PHP, some people in the ASP community developed ASP template classes using replacement methods such as phplib. Because ASP is not very powerful in character processing, therefore, the speed is affected. Such templates are not widely used at present. For example:
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 " ) ' User-Defined Functions: Load template files 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 only shows the idea of the current ASP template. Some CMS systems of ASP version have embedded logical control over the template. Although the logic and interface can be separated, however, this kind of template has the problem that the template needs to be parsed every time using ASP. The program is equivalent to parsing twice, and when there are many content to be replaced, the performance will be reduced. in addition, the server must support one type of component (FSO, ADODB, and XMLHTTP) to load the template ).
For reference to compiled templates, I introduced this idea in ASP and proposed a template system with excellent functions and performance in ASP. The following code is used: 1 <! -- Template.html -->
2 < Html >
3 < Head >
4 < Title > <% = Title %> </ Title >
5 </ Head >
6 < Body >
7 <! -- <%
8 'If logic control, of course, the for and while loops are also processed here. Isn't it easy,
9 'Make HTML comments on the logic. In DW (Dreamweaver), there will be no deformation for ASP placeholders controlled by the logic, and an ASP flag will be displayed for other variables for ease of modification.
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 = " Music "
6 Book = " Books "
7 % >
8 < ! -- # Include file = " Template.html " -->
idea: ASP files are routinely processed by logic, operations, and no need to worry about the display layer. Of course, the variables to be displayed must be combined with the display layer (the same is true for PHP ), in the template file, use <%> to directly control the display of variables and logical control. html annotator is used for non-displayed logical control operators Comment out. Of course, it is okay not to comment out. This way, at the end of the ASP file, " "realizes the combination of templates and ASP files, achieves the separation of code and presentation layer, and does not use ASP to load templates here, then, it will waste unnecessary ASP resources. all of these processes are saved. You will find it easier to write ASP files, because you no longer need to control the replacement and display the logic. Direct execution in ASP must be faster and more stable than replacement. you must also load a component when loading a template.
here, you may understand the essence of this template. It is just a design mode, not a template engine that uses a template class for processing.