Skip to content

Partials

Craig edited this page Oct 17, 2017 · 1 revision

Nettle supports partial rendering with registered templates. A template can be registered as follows:

var partialContent = @"Partial content...";
var compiler = NettleEngine.GetCompiler();

// NOTE: Partial names must be alphanumeric and cannot contain spaces.
compiler.RegisterTemplate("SamplePartial", partialContent);

Template views contained in a directory can be automatically registered as follows:

var compiler = NettleEngine.GetCompiler();

compiler.AutoRegisterViews("../Templates");

A template view must use the file extension .nettle and the filename is used as the registered template name, therefore it must be alphanumeric and cannot contain spaces.

The syntax for rendering a partial is:

{{> PartialName Model}}

The model is optional and if left empty, the current templates model is used instead. The model can be any value assignable to a variable, including a variable reference.

Clone this wiki locally