Note that there are some explanatory texts on larger screens.

plurals
  1. POMigrating from Spark to Razor
    text
    copied!<p>We are gradually migrating a Spark based project to use Razor and I have come across something I can't seem to find an answer to. </p> <p>My line in my Spark master calls a sub View like so </p> <pre><code>&lt;Sidebar&gt; &lt;segment name="header"&gt; &lt;div&gt; &lt;!-- header content--&gt; &lt;/div&gt; &lt;/segment&gt; &lt;segment name="content"&gt; &lt;div&gt; &lt;!-- content content--&gt; &lt;/div&gt; &lt;/segment&gt; &lt;/Sidebar&gt; </code></pre> <p>The Sidebar spark looks like so</p> <pre><code>&lt;div id="sidebar" &gt; &lt;div class="header"&gt; &lt;render segment="header"&gt; &lt;!-- placeholder --&gt; &lt;/render&gt; &lt;/div&gt; &lt;div class="ui-layout-content content"&gt; &lt;render segment="content"&gt; &lt;!-- placeholder --&gt; &lt;/render&gt; &lt;/div&gt; </code></pre> <p></p> <p>This renders with the content from the first section displayed in the layout from the second. Is there some way I can recreate this using Razor. I can see that I need to use Partials, but I can't see how to pass the content into the sidebar subview. </p> <p>Essentially I'm trying to recreate the functionality that Spark calls Segments (or previously Sections) <a href="http://sparkviewengine.com/reference/elements#segmentpreviouslyknownassection" rel="nofollow">http://sparkviewengine.com/reference/elements#segmentpreviouslyknownassection</a></p> <p>EDIT: More information. I have an Index.cshtml that gets it's layout from Application.cshtml. In here I have the markup code that goes into the Sidebar.cshtml partial. </p> <p>If I add put <code>@section header</code> (which is rendered in the Sidebar.cshtml) in my Index.cshtml file it doesn't recognise it as a valid section. I have <code>@RenderSection("header", false)</code> in my Sidebar.cshtml file. </p> <p>How do I tie these 2 together?</p> <p>So my hierarchy is as follows</p> <p>Application.cshtml -- Global page layout<br/> Index.cshtml -- Page layout including content for the sidebar<br/> Sidebar.cshtml -- Template / layoout for sidebar content from Index.cshtml<br/></p> <p>For example </p> <p>in Index.cshtml</p> <pre><code> @RenderPage("Sidebar") @section SidebarHeader { &lt;!--Title or something --&gt; } @section SidebarContent { &lt;!--Content --&gt; } </code></pre> <p>Then in Sidebar.cshtml</p> <pre><code> &lt;div class="header"&gt; @RenderSection("SidebarHeader", false) &lt;/div&gt; &lt;div class="ui-layout-content content"&gt; @RenderSection("SidebarContent", false) &lt;/div&gt; </code></pre> <p>The idea is that I can have a template in a sub-view that is populated with the content from the view. Meaning that I can template areas for other pages across the site. Eg. The sidebar content on another page will need the same format, but different content. </p>
 

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