Click or drag to resize
HelpersRenderSection Method
Renders the named section.

Namespace: HandlebarsDotNet.Mvc
Assembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntax
public static void RenderSection(
	TextWriter writer,
	Object context,
	params Object[] arguments
)

Parameters

writer
Type: System.IOTextWriter
The TextWriter provided by HandlebarsDotNet
context
Type: SystemObject
The context (model) provided by HandlebarsDotNet
arguments
Type: SystemObject
The arguments from the view, provided by HandlebarsDotNet
Remarks
This helper is among the ones registered if RegisterSectionsHelpers is called. If so, it is registered as rendersection but you can choose your own name for this:
C#
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("rendersection", HandlebarsDotNet.Mvc.Helpers.RenderSection);
It works like Razor's RenderSection method. For a nice write-up, see https://weblogs.asp.net/scottgu/asp-net-mvc-3-layouts-and-sections-with-razor.

Usage

{{rendersection [name] [required=true|false])}}

Arguments

name
string (required) - The name of the section.
required
bool (required) - Whether the section must have been defined. Specifying required is not required but if specified it must be true (default) or false.

Description

Renders a named section.
If the section hasn't been defined and required is (which it is by default) an exception is thrown.
If the section hasn't been defined and required is nothing is rendered.
If the section has been defined it is rendered HTML-escaped, unless you use the triple-mustache: {{{rendersection ...}}}.
Examples
view.hbs
{{!< default}}
{{#definesection "sidebar"}}
    For more info, see<br />
    <a href="link1.html">Link 1</a><br />
    <a href="link2.html">Link 2</a><br />
{{/definesection}}
~/Views/_Layouts/default.hbs
{{#if (issectiondefined "sidebar")}}
    <div id="sidebar">
        {{{rendersection "sidebar"}}}
    </div>
{{else}}
    <p>Default sidebar content...</p>
{{/if}}
See Also