Document directory
- I. Value tag
- I. Component labels
- Ii. Bind tags to values
- 3. Custom tags
I wrote a website construction system myself. Why should I write a website construction system on my own instead of using an open source website (my website will be open source in the future ), many people have asked me about this. Of course there is a reason. I will explain it later. Today, let's talk about the development of the template engine in the website construction system.
The website creation system is based on. net. For ease of use, I have also compiled the template processing function. Of course, I also need to generate static webpages using some tagging languages. I use a language label similar to zhimeng. Of course, I also have my own characteristics. It is quite different from zhimeng in realizing the functions. I will give you an overview of the implementation ideas. I will write the first article today, first introduce my template tag, and then gradually explain how to implement its functions.
Tags are classified into three categories:Value tag, component tag, custom tag
I. Value tag
Without any attribute, it can appear anywhere in HTML, similar to the public value output in. net.
For example:
{% = SiteName %} output website name
Value labels are classified into global value labels and local value labels, which are used in the same way.
1. Global Value tag
Global Value tag refers to the value that can be referenced on all pages of the website.
Website name {% = SiteName %} in the preceding example}
2. Local value tag
A local value tag is a reference value in a specific environment. For example, if the page of a news topic is known to be a news topic, you can directly reference {% = NewsColumnName % }, displays the name of the current topic. Supports formatting.
For example:
{% = NaTitle %} output the title of a news article
{% = NaCrtTime: yyyy-mm-DD %} the time when the news article was created and formatted as yyyy-mm-DD % }.
I. Component labels
The component tag is mainly used within the page body to display more complex content. It can contain attributes. Similar to. net components. Originally intended to be <angle brackets. In order to maintain consistency with html tags, brackets were used to solve the search efficiency problem.
Such as the news list,
[List: NewsArticle count = "10" sort = "1" class = "news" title = "news list"]
<A href = "news_000000000000newsid00000000.html" >{%# newsTitle %}</a>
[/List: NewsArticle]
The generated HTML code is as follows:
<Dl count = "10" sort = "1" class = "news">
<Dt> News list </dt>
<Dd> <a href = "news_1.html"> the north sand and dust weather will continue </a> </dd>
......
</Dl>
In the preceding tag, the attribute is optional;
Components are divided into the following categories based on their specific usage:
1. List tags
For example:
List: NewsArticle. The article List is displayed cyclically and HTML tags of dl and dd are generated. pagination is supported.
You can set attributes to display how many pieces of information and the articles under the topic;
The html code in the component tag is output cyclically.
2. Loop tag
The cyclic tag function is similar to the List function, but paging is not supported.
Repeat: NewsArticle. It displays the article list cyclically and outputs only. No redundant HTML tags are generated.
3. Single Information tag
Content tag. For example, output a news article with id 2.
[Details: NewsArticle id = "2"]
......
[/Details: NewsArticle];
The Html code in the component tag is synchronously output. Because it is not a list component, it is not output cyclically.
4. Short tag
The label prefix can be abbreviated.
List abbreviations: l, li
Repeat short for r and rp
D, de
Tag suffixes also support simplicity, such as newsArticle, which can be abbreviated as na;
View the Template system configuration file Template. config.
Ii. Bind tags to values
Displays the attributes of the current record in the component tag.
For example, {% # newsTitle %} in the previous example }. Supports formatting.
For example: {% # crtTime: yyyy, M, D, %}. The output is January 1, March 1, 2013.
For example: {% # index: 00%} output 01
Similar to <% # Eval ("crtTime", "{0: yyyy, M, D,") %>
3. Custom tags
It is mainly used to display some common content, such as the top and bottom of the page. Similar to. net Component reference.
For example, at the top of the page
{% @ PageTop %}
All links in custom tags, such as hyperlinks and image links, are automatically converted based on the current page paths of custom tags.