CodeSmith BASICS (5)

Source: Internet
Author: User
This article describes the syntax in the CodeSmith template.
Code tag
<%> Tag
You can place any number of codes in it, but it cannot be directly output to the template.

<% Foreach (ColumnSchema column in SourceTable. Columns) {%>
<% = Column. Name %>
<% }%>

<% = %>Tag

Output a string in the template. <% = Column. Name %>

Script tag

This label can contain a piece of code, but it does not directly affect the output template. You can place some helpful methods in it, and then you can call it in various places of the template. This parameter runat = "template" must be included in the script tag; otherwise, it will be processed as normal text.

Example:

1 <script runat = "template">
2 private string GetColumnName (ColumnSchema cs)
3 {
4 return cs. Name;
5}
6 </script>
7
8 <% foreach (ColumnSchema cs in SourceTable. Columns) {%>
9 <% = GetColumnName (cs) %>
10 <% }%>

Using tags can greatly reduce code and make templates easier to read and manage.

IncludeTag

Like ASP. NET, a template can contain some text files, but like ASP. NET, it does not always achieve your goal.

Example:

<! -- # Include file = "myfile. inc" -->

Sometimes, you can reference the functions of one component in multiple templates and call the methods. In this case, we reference the component. However, in some cases, applying the Include label can achieve better results.

CommentTag

Annotation label, which has been introduced in the front.

Example:

<% -- This is a comment -- %>

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.