ASP.NET MVC 3 では@section
、ビュー内にを含めることができます。
@section SideBar {
<p>Some content</p>
<p>Some more content</p>
}
<p>Body content</p>
次に、マスター ビューで、これを使用してレンダリングします。
<div id="sidebar">
@RenderSection("SideBar", false)
</div>
@RenderBody()
Model Glue フレームワークでこれに相当する ColdFusion は何ですか? ビューで単純な変数を設定できることはわかっています。
<cfset event.setValue("section", "Tables")>
次に、マスター テンプレートで次のように使用します。
<cfif event.exists("section")><h3>#event.getValue("section")#</h3></cfif>
ただし、これはワンライナーと単純な文字列に対してのみうまく機能します。私がやりたいのは、HTML ブロック全体を含めることです。これを達成する最善の方法は何ですか?これは理論的にはうまくいくと思います:
<cfsavecontent variable="sidebar">
<p>Some content</p>
<p>Some more content</p>
</cfsavecontent>
<cfset event.setValue("sidebar", sidebar)>
しかし、もっと良い方法がないか考えてみました。
編集:
Adam Cameron の回答に応えて、Model Glue は、私が知る限り、個別のファイルを 1 つのテンプレートに結合する機能のみをサポートしています。
SideBar.cfm:
<p>Some content</p>
<p>Some more content</p>
Page.cfm:
<p>Body content</p>
ModelGlue.xml:
<event-handler name="page.text">
<views>
<include name="sidebar" template="SideBar.cfm"/>
<include name="body" template="Page.cfm"/>
<include name="main" template="main.cfm"/>
</views>
</event-handler>
main.cfm:
<cfoutput>#viewCollection.getView("sidebar")#</cfoutput>
<cfoutput>#viewCollection.getView("body")#</cfoutput>
ビュー内でサイドバーのコンテンツを宣言できるようにする必要がありpage.cfm
ます。ここで考えられるのは、メイン テンプレートのどこかに div があり、小さな HTML スニペット (たとえば、テキストの説明とリンクを含む画像) を許可し、任意のビューに入力できるということです。Page1.cfm
and Page1SidebarContent.cfm
、Page2.cfm
andなどのようなものがあるのは意味がありませんPage2SidebarContent.cfm
...