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 -- %>