 | HelpersIsSectionDefined Method |
Returns a value to be used within an #if subexpression whether a section name has been defined.
Namespace: HandlebarsDotNet.MvcAssembly: HandlebarsDotNet.Mvc (in HandlebarsDotNet.Mvc.dll) Version: 1.0.0-beta
Syntaxpublic static void IsSectionDefined(
TextWriter writer,
Object context,
params Object[] arguments
)
Public Shared Sub IsSectionDefined (
writer As TextWriter,
context As Object,
ParamArray arguments As Object()
)
public:
static void IsSectionDefined(
TextWriter^ writer,
Object^ context,
... array<Object^>^ arguments
)
static member IsSectionDefined :
writer : TextWriter *
context : Object *
arguments : Object[] -> unit
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
issectiondefined but you can choose your own name for this:
var hbsve = new HandlebarsViewEngine();
hbsve.RegisterHelper("issectiondefined", HandlebarsDotNet.Mvc.Helpers.IsSectionDefined);
It works like Razor's IsSectionDefined method. For a nice write-up, see
https://weblogs.asp.net/scottgu/asp-net-mvc-3-layouts-and-sections-with-razor.
Usage
{{#if (issectiondefined [name])}} ... {{/if}}Arguments
- name
- string (required) - The name of the section.
Description
This helper checks if a named section has been defined, and returns a truthy value if so. That value can be used in an
{{#if}}-test to for example render the section or default content as in the example below.
Examples{{!< 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