Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is ColdFusion Model Glue's equivalent to ASP.NET MVC 3's @section?
    primarykey
    data
    text
    <p>In ASP.NET MVC 3, you can have an <code>@section</code> within a view:</p> <pre><code>@section SideBar { &lt;p&gt;Some content&lt;/p&gt; &lt;p&gt;Some more content&lt;/p&gt; } &lt;p&gt;Body content&lt;/p&gt; </code></pre> <p>Then in the master view, you would use this to render it:</p> <pre><code>&lt;div id="sidebar"&gt; @RenderSection("SideBar", false) &lt;/div&gt; @RenderBody() </code></pre> <p>What would be the ColdFusion equivalent of this in the Model Glue framework? I know I can set simple variables in the view:</p> <pre><code>&lt;cfset event.setValue("section", "Tables")&gt; </code></pre> <p>Then use them in the master template like so:</p> <pre><code>&lt;cfif event.exists("section")&gt;&lt;h3&gt;#event.getValue("section")#&lt;/h3&gt;&lt;/cfif&gt; </code></pre> <p>But this only works well for one-liners and simple strings. What I'd like to do is include an entire HTML block. What is the best way of accomplishing this? I think this would work in theory:</p> <pre><code>&lt;cfsavecontent variable="sidebar"&gt; &lt;p&gt;Some content&lt;/p&gt; &lt;p&gt;Some more content&lt;/p&gt; &lt;/cfsavecontent&gt; &lt;cfset event.setValue("sidebar", sidebar)&gt; </code></pre> <p>But I was wondering if there's a better way of doing it.</p> <p><strong>Edit:</strong></p> <p>In response to Adam Cameron's answer, Model Glue, from what I can tell, only supports the ability to combine separate files into one template:</p> <pre><code>SideBar.cfm: &lt;p&gt;Some content&lt;/p&gt; &lt;p&gt;Some more content&lt;/p&gt; Page.cfm: &lt;p&gt;Body content&lt;/p&gt; ModelGlue.xml: &lt;event-handler name="page.text"&gt; &lt;views&gt; &lt;include name="sidebar" template="SideBar.cfm"/&gt; &lt;include name="body" template="Page.cfm"/&gt; &lt;include name="main" template="main.cfm"/&gt; &lt;/views&gt; &lt;/event-handler&gt; main.cfm: &lt;cfoutput&gt;#viewCollection.getView("sidebar")#&lt;/cfoutput&gt; &lt;cfoutput&gt;#viewCollection.getView("body")#&lt;/cfoutput&gt; </code></pre> <p>I need to be able to declare the sidebar content <strong>within</strong> the <code>page.cfm</code> view. The thought here is that there will be a div somewhere in the main template that allows for a small HTML snippet, say an image with a text description and a link, which any view can populate. It wouldn't make sense to have something like <code>Page1.cfm</code> and <code>Page1SidebarContent.cfm</code>, <code>Page2.cfm</code> and <code>Page2SidebarContent.cfm</code>, etc...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload