Use the page template engine to generate site views

Source: Internet
Author: User

Recently, new companies mainly work on static pages and write planning. The other is to learn about the communityserver project. It has been a month since we added up. On Saturday, I went to shangdiqi Street, a company. After talking with others, I found that this template class has been in use for a long time. When I came back, I thought I should add a feature that the template class always needed. Is to support information carriers. That is to say, in the custom tag parsing function, we can obtain data from various types of information carriers that have recently been defined by the outside world. After the information carrier class is added, it can be said that the template engine is used to develop pages, which is more practical.

In which blog Project (www.93913.com) is developed with the simple template engine ). The tag analysis interface can be expanded at will. Therefore, we can naturally upload various information carrier classes to the template engine. However, in this template class, the underlying class is fixed. It was originally intended to reduce the resource consumption of objects. You have to make all classes into sealed class. In addition, at that time, we basically did not consider using the forced type conversion with reduced efficiency. In this way, a difficult technical point is set for implementing this function. I made a big modification to the original structure last night. Change the underlying class to an abstract class. A forced type conversion is used. Modified the cache of the delegate object. This solves the problem of directly referencing the external information carrier class in the tag parsing function.

Let's talk about the idea of using the template engine for development. There may be a lot of errors and we will approve them.

When you see a page. In our portal, we cut out the page layout and dynamic part. Put it in a file. This file is the template file of our portal. Cut out the dynamic part of the file. Put a label on the position of the dynamic part first (what is a label and how to use it, go to vitality2007.cnblogs.com on my blog ). Add a tag parsing function corresponding to the tag in the tag parsing class.

In this way, we can say that the page layout and page function are separated temporarily. The layout is determined by the HTML code in the template file. The function is determined by the tag in the template file. (Of course, the data output after tag parsing cannot be complete. This can actually be done. However, too many tags are generated, which are generally not used. Most of the output after tag conversion is a mixed string of data and HTML. We can pass the style and parameters as tag parameters to control the layout and content of the output part of Tag Parsing)

The feature is independent and a problem is found. He has less contact with the page. The data information must be passed to the tag parsing function through the attributes of the template class. To reduce the number and flexibility of attributes. Naturally, a large number of classes are written. They have many attributes. class objects are generated to retain data. This class object is called an information carrier class.

Now the process is clear. The page layout has been extracted and placed in the template file. All the page functions have been extracted and the corresponding functions have been written in the tag parsing class at the logic layer.
1. On the UI Layer page, I first obtain all the parameters that I want. It is passed to the data layer through the logic layer.
2. The data layer generates information carrier objects for the corresponding request. What information does it contain?
Write it as sealed class and implement the garbage collection interface. Convenient analysis.
3. The information carrier class is passed to the logic layer and together with the template file path information, it is passed to the template engine.
4. In the tag parsing function, you can obtain information carrier data and transmit other recent data. Identify and process data. The layout is displayed, and all logical processing is implemented here.
5. data parsed by tags are merged in the returned template engine and template files. The merged data is displayed on the page on the UI Layer.

The corresponding Ajax processing process is similar. All pages of such a site are generated by the template engine. The layout function data is separated. And cache is used more. Increase the speed as much as possible. It is easier to modify site maintenance.

There will be a probability of less than 0.5%. Some template engine source information will be displayed on the generation page, but the information can only be displayed after the first custom parsing tag outside the loop. The information format is as follows. Write to death in code.

"<Span style = 'display: none; width: 0px; Height: 0px; '> <a href = 'HTTP: // vitality2007.cnblogs.com' Title = 'asp. net Development template engine '> Asp.net development template engine </a> </span>"

The source information of the add-up template engine cannot be displayed more than 0.25%

There is no new time for this example. I only made the simplest example and only made necessary modifications this time. Create a virtual directory named templateweb.

I will create a new example later.
/Files/vitality2007/templateweb.rar

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.