用户名: 密   码: 注册 忘记密码
模版入门
模版函数库
模版中心
语法
代码标签
<% %>标签
可以放置任意数量的代码在其中,但并不能直接输出到模版中。
<% foreach (Field fd in tb.Fields) { %>
<%= fd.Name %>
%> } %>
<%= %>标签
在模版中输出一个字符串。上例中的<%= fd.Name %>
脚本标签
在这个标签中可以包含一段代码,但是他不直接影响输出的模版。可以放置一些比较有帮助的方法在其中,然后在模版的各个地方可以调用它。在脚本标签中必须包含这个参数runat=”template”,否则他会被处理成普通文本。
例:
<script runat="template">
private string GetFieldName(Field fd)
{
      return cs.Name;
}
</script>
 
<% foreach (Field fd in tb.Fields) { %>
<%= GetFieldName(fd) %>
<% } %>
如何在模板中添加注释
SpDevelop:
<%-- Comments --%>
C#:
<%-- // Comments --%>
<%-- /* Comments */ --%>
解决ASP.NET中标签<%重复问题
        先将ASP.NET中使用的这个重复标签写成<%%,避免在生成代码时由于是标签重复引起的编译错误或生成错误。
如何声明一个常量
<script runat="template">
private const string MY_CONST
= "example"
</script>
如何将属性设置成选择一个文件夹的路径
<script runat="template">
private string _outputDirectory ;
[ Editor ( typeof ( System.Windows.Forms.Design.FolderNameEditor),
  typeof ( System.Drawing.Design.UITypeEditor ))]
public string OutputDirectory
{
      get { return _outputDirectory ;}
      set { _outputDirectory= value;
}
</script>
怎样调用子模板
<% OutputSubTemplate(); %>
<script runat="template">
private CodeTemplate _mySubTemplate;
[Browsable(false)]
public CodeTemplate MySubTemplate
{
    get {
          if (_mySubTemplate == null)
          {
               CodeTemplateCompiler compiler = new CodeTemplateCompiler(this.CodeTemplateInfo.DirectoryName + "\\MySubTemplate.cst");
               compiler.Compile();
               if (compiler.Errors.Count == 0) 
              {
                    _mySubTemplate = compiler.CreateInstance();
              }
              else
             {
                   for (int i = 0; i < compiler.Errors.Count; i++)
                  {
                        Response.WriteLine(compiler.Errors[ i].ToString());
                  }
            }
        }
        return _mySubTemplate;
    }
}
public void OutputSubTemplate()
{
      MySubTemplate.SetProperty("InsertPrefix", "Insert");
      MySubTemplate.Render(Response);
}
</script>
在加载模板时默认加载的命名空间Namespaces和组件Assemblies
组件:
  • mscorlib
  • System
  • System.Xml
  • System.Data
  • System.Drawing
  • System.Windows.Forms
  • System.Web
  • System.Design
  • System.Web.RegularExpressions
  • System.Drawing.Design
  • SchemaExplorer
  • SpDevelop.Base
  • Sp.DbPlugin
应用表字段中的特殊属性
当您在设计表时可以自定义字段的一些属性,如下图:

图中设置了List=0; 我们可以在模版中通过LoadCodeProperty("List")来获取:
<%
DbEntity db = Template.GetDataBase("databaseProjectName");
Table tb = db.Tables["TableName"];
if( tb != null)
{
     Field fd = tb.Fields["FieldName"];
      if( fd != null)
     {
            Response.WriteLine(tb.LoadCodeProperty("List"));
     }
}
%>
Copyright © 2005-2009 SpDevelop Software, All Rights Reserved.