一个模板多个组成
2009-05-11 18:26 宝宝合凤凰 阅读(203) 评论(0) 收藏 举报<%@ CodeTemplate Language="C#" TargetLanguage="HTML" ResponseEncoding="UTF-8"%>
<%@ Property Name="Title" Type="System.String" Optional="False" Category="Options" Description="Page title." %>
<%@ Property Name="Placeholder" Type="System.String" Optional="True" Category="Options" Description="Main placeholder text." %>
<%@ Register Name="Header" Template="Header.cst" MergeProperties="True" ExcludeProperties="Test" %>
<%--
Register
Name:代表被引入的模版的名称。它可以被用作创建一个模版的实例。
Template:被引入模版文件的相对路径,它可以与当前的模版一起被动态的编译。
MergeProperties:设置成True时,所有被引用的面板的属性将被动态的添加到当前模版中。
ExcludePorperties:当使用MergeProperties时,你可能不需要某些属性被添加到当前模版中。将不需要的属性以逗号分隔放在这里,*号可以被用作通配符使用。注意,调用表中没有Test属性.被调用表中有Test
--%>
<% OutputHeader1(); %>
<body>
<h1>**************<%= Title %></h1>
<p><%= Placeholder %></p>(<%=Test%>这是用Test的方法)
</body>
</html>
<script runat="template">
public void OutputHeader1()
{
//Header header = this.Create<Header>();
// include the meta tag
//header.IncludeMeta = true;
// copy all properties with matching name and type to the sub-template instance
//this.CopyPropertiesTo(header);
// render the sub-template to the current output stream
//header.Render(this.Response);
Header mySubTemplate = new Header();
// set an individual properties value.
mySubTemplate.Title = "SomeValue";
// copy all properties with matching name and type to the sub template instance.
this.CopyPropertiesTo(mySubTemplate);
// render the template to the current templates Response object.
mySubTemplate.Render(this.Response);
// render the template to a file.
mySubTemplate.RenderToFile(@"C:\dir\SomeFile.txt",true);
}
</script>
==============================
<%@ CodeTemplate Language="C#" TargetLanguage="HTML" ResponseEncoding="UTF-8" %>
<%@ Property Name="Title" Type="System.String" Optional="False" Category="Options" Description="Page title." %>
<%@ Property Name="CharSet" Type="System.String" Optional="False" Default="windows-1252" Category="Options" Description="Character set for the page." %>
<%@ Property Name="IncludeMeta" Type="System.Boolean" Default="True" Optional="False" Category="Options" Description="Include meta tags." %>
<%@ Property Name="Test" Type="String" Default="" Optional="False" Category="" Description="" OnChanged="" Editor="" EditorBase="" Serializer="" %>
<html>
<head>
<% if (IncludeMeta) { %>
<meta http-equiv="Content-Type" content="text/html; charset=<%= CharSet %>">
<% } %>
<title><%= Title %></title>
</head>
<%= Title %>
Next, the main template generates the body of the HTML file. Note that it uses the sub-template to generate the header:
================================================
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>父模板中的</title>
</head>
父模板中的
Next, the main template generates the body of the HTML file. Note that it uses the sub-template to generate the header:
<body>
<h1>**************父模板中的</h1>
<p>888888</p>
</body>
</html>
结果是被合成了一个文件,并且父的属性覆盖了子属性,就是父中没有属性而子中有的,在父中的属性面板中也得重新给值{我也不明白}
浙公网安备 33010602011771号