Template mechanism of small Loach anatomy Series

Source: Internet
Author: User
Tags xslt

 

In order to implement a good template mechanism for small Loach, it took a lot of time to analyze the maturity and popularity of the Internet.ProgramIncluding blog, CMS, shop, BBS/. net, PHP, ASP, etc. The following are summarized:

 

1,CSS

Different CSS files are loaded to achieve different display effects.

If you are familiar with CSS, you will know that CSS is powerful. The default theme of Asp.net is based on this implementation.

 

Advantage: easy to maintain and fast

Disadvantage: The 2/8 principle can implement most of the functions and is not flexible enough.

 

2,Template engine

By loading different template files (the template file content can be different), the template engine uses its own language mechanism to dynamically replace Data to achieve different display effects.

 

Advantages: flexible, can meet most of the needs

Disadvantage: it affects performance and requires the introduction of a third-party template engine (which can be developed by yourself) to increase complexity.

 

3,. AscxUser Control, Master page(. NetUnique Platform)

 

Different. ascx user controls are loaded to achieve different display effects. Of course, the. master page can also be dynamically loaded.

The principle is similar to that of using a third-party template engine.

 

Advantage: the. NET language is more flexible than the template engine and can meet any needs

Disadvantage: the reflection mechanism is used to affect the performance (it is said that it has not been verified). There are many. NET features, which are unfriendly to the artist.

 

4,Generate. AspxFile

You need to use a template engine to generate a. aspx file, and use URL rewriting to load different. aspx files. The usage is irrelevant to the template engine and template file.

 

Advantages: flexible and fast

Disadvantage: it is relatively difficult to maintain. After modifying the template, You need to regenerate the. aspx file and add it to the third-party template engine to increase complexity.

 

5,XML + XSLT

Glossary: XSL refers to Extensible Stylesheet Language, and XSLT refers to XSL conversion.

The design idea is the same as that of the template engine, but XSLT is a general standard.

 

Advantages: Standard, cross-platform, cross-language

Disadvantages: not flexible enough, error-prone, complicated for the artist

 

The question is, which one is more suitable for small Loach? Community Server, blogengine. net and other foreign programs, Lao Nong began to select 3rd types, by dynamically loading different user controls to implement the template mechanism, the function is very powerful, in addition, this method is used in a long internal development phase, and it is also at this stage, in communications with colleagues and friends of other professions, I think this may not be the most appropriate method (practice is true). There are too many theme designers for general users, especially theme designers. NET features will make them eye-catching.

 

The positioning of small loach is a mature, universal, blog program for all groups, and finally focuses on the template engine,

Currently, the main template engines of the. NET platform include nvelocity and stringtemplate. After many tests and evaluations, nvelocity is selected. Of course, nvelocity cannot be ruled out and you have time to build your own wheels.

 

Nvelocity originated from Java and has a long history and elegant syntax, reducing the cost of repetitive Learning

 

See the followingCodeUsed to output the latest logs (simple is beautiful ):

 

 
<Div id = "recentposts" class = "widget">  

 

According to the feedback statistics since the release, the results are good. Let's take a look at it. ^_^

 

Appendix:

Source code download: http://files.cnblogs.com/wei/Loachs_1.2_src.rar

Http://www.loachs.com/

 

QQ: 12018034

 

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.