On the template engine-go beyond the template engine

Source: Internet
Author: User
After talking for a long time, it seems that I still did not understand it. It is estimated that the organizational capacity of the non-verbal language has deteriorated for a long time. In fact, it is very simple to say. With so many template engines (I wrote one to catch up with the project), I found myself doing something stupid. Let the template engine support judgment, loop, branch, and different enhancement of a variety of tags, tags are becoming more and more like Asp.net control labels, and APIs become more and more complex. Maybe the last time we looked back, we realized something that existed long ago in Asp.net. So why don't we just use it now?
I will explain my point of view in several parts below. I reiterate that I am not saying that the template engine is not used. My point is that the aspx file itself is the best template engine. As for how to use it, I will provide a method for my own use later. Of course, you can also summarize your own:
I. weakness of the template engine
Many PHP engineers are familiar with the template engine, such as smarty. It seems that I still know nothing and have never heard of it. Of course, the advantages of the template engine do not need to be discussed. If there is no advantage, there will be no value at all. The first challenge is the cost of learning. To be honest, as far as the syntax of the current template engine is concerned, what is getting closer and closer Programming Language This is to reduce the learning cost. The following is a piece of smarty Template Code : {* Monte OHRT March 4, 2002 *}
{* $ Cols is the number of columns you want *}
< Table Border = 1 >
< Tr >
{Section name = numloop loop = $ data}
< TD > {$ Data [numloop]} </ TD >
{* See if we shoshould go to the next row *}
{If not ($ smarty. Section. numloop. rownum mod $ Cols )}
{If not $ smarty. Section. numloop. Last}
</ Tr > < Tr >
{/If}
{/If}
{If $ smarty. Section. numloop. Last}
{* Pad the cells not yet created *}
{Math equation = "N-A % N" n = $ Cols A = $ data | @ count assign = "cells "}
{If $ cells ne $ Cols}
{Section name = pad loop = $ cells}
< TD > & Nbsp; </ TD >
{/Section}
{/If}
</ Tr >
{/If}
{/Section}
</ Table >

Of course, if you are used to the same school, you don't think it's okay, but for those who are not familiar with it, or those who have no time to study (such as me, this code is the same as tianshu without careful research. For artists, it is even more common to have tianshu. No wonder the webmaster Of a smarty tutorial website in China said: Hurry and learn it. This is hard to learn and the salary is high. For it, the more difficult it is to learn, the higher the salary, as if it is to make money with yourself. The same is true for other template engines. I will not list the code one by one. In addition to the template language, the template engine APIS also need to be learned. SoProgramBoth members and the artist said that this is a dual burden.

The second is the compilation support and tool support. Smarty is not bad. There is a plug-in Dreamweaver, but it is spoiled by smart perception menu and compilation period detection. neter and javaer are still too immature (Please kill me without the smart perception menu ). Let's look at the document and write the code, and run it to see that the result looks like the last century's way of working. Maybe one day various open source enthusiasts can come up with various plug-ins to solve this problem, but who has the time to wait and who has the time to try the plug-in one by one?

Ii. incorrect use of the template engine
Currently, most template engines combine data and templates to generate a bunch of HTML results (XML or other things are not considered for the moment ). One of the mistakes is that the template engine is mistaken for a skin replacement engine. For example, the most typical idea is:
#1 floor iiduce@163.com wolf strong
How can I use aspx as a template to implement coexistence of multiple sets of templates in the same CS code to quickly change the template.
--------------------------------------------------------------------------------- Gorgeous split line --------------------------------------------------

The most common use of the template engine is the CMS system, which generally generates static pages to improve efficiency. Another is that many MVC frameworks use the template engine to implement the view. However, if the page is complex and involves a large number of object assignments, loops, and controls, it may cause efficiency bottlenecks due to a large amount of reflection (I have not tested this and can test it if I am interested ). These two points are basically directly generating the final result. Skin replacement and other functional things I personally think should not be the main design purpose of the template engine.

Iii. feasibility and advantages of using the ASPX page as the template engine
The feasibility will not be mentioned. Of course it is feasible, and ASP. net mvc is now using the ASPX page as the view layer. The advantages are as follows:

    • Learning efficiency

For programmers, there is no need to learn it at all. It would have been, of course, the highest learning efficiency.

    • Tool support and compile-time detection

Both Dreamweaver and vs. NET are supported, and the smart perception menu and compilation check both exist. Very nice

    • Supports ASP. NET controls

Some people say that the control is not convenient, so you don't actually need the control, directly on the page <%
If(Helper. islogin ()){
User u=Helper. getlogineduser ();
%>
Your name is: <% = U. Name %>
<% } %>

Is it the same? Why should we put ourselves in the dead?

Some people say that system. web should be introduced in the XX layer. In fact, this problem is a bit funny. MVC and layering are totally different. In the logic layer, system is introduced. the Web is not a problem. If you want to use stringtemlate as the template engine, you must also introduce the stringtemplate DLL. If you use the ASPX page as the template engine, introduce the system. isn't the Web reasonable?

Finally, how can I use it?

The template is still called through server. execute is mainly used to solve the problem of calling files. Instead of using the load ascx file method, I defined a placeholder. After executing this page, I searched for several placeholders, call Other templates based on placeholders, and replace the execution results.

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.