-
Notifications
You must be signed in to change notification settings - Fork 9
Template Flags
Craig edited this page Nov 11, 2017
·
5 revisions
You can add flags to your template to change the way the Nettle rendering engine behaves. The syntax for a using a flag is {{#FlagName}}. Flags must be declared once for each template. The following flags are currently supported:
Name | Description |
---|---|
IgnoreErrors | Ignores all errors generated by the rendering engine. Only errors generated by the compiler will be raised. If this flag is enabled, code blocks that generate an error won't be rendered and an empty string will be inserted in its place instead. |
DebugMode | Appends debug information to the end of the generated output. This includes the render time, all properties and variables from the template context. |
AllowImplicitBindings | Allows variables or model properties to be used without declaring them. This could be useful the model is dynamic or unknown until runtime. |
EnforceStrictReassign | Ensures that a new value assigned to a variable is also assignable to the type that was initially set when the variable was defined. Assignable means either the type is the same or a more derived type. |
DisableModelInheritance | Disables the inheritance of variables and properties when creating nested models. Nested models are created when a nested code block is run (such as an each, if or render partial statement) and be default, the variable and property values in the parent model are passed to the new child. |
AutoFormat | Automatically formats the templates output by removing extra line breaks and tabs which exist because of the Nettle code. This could be useful when the template output is intended to be used as plain text. |
Minify | Minifies the template output by removing all tabs and line breaks. This overrides the AutoFormat flag. |
UseUtc | Ensures date and time is expressed as the Coordinated Universal Time (UTC). |
The following example demonstrates the use of the AutoFormat flag:
{{#AutoFormat}}
{{each $.Names}}
{{$}}
{{/each}}
Given an array Names = ["Craig", "John", "Simon"], the code above would produce the following output:
Craig
John
Simon
Without AutoFormat, the output would look like this:
Craig
John
Simon
The following example demonstrates the use of the DebugMode flag:
{{#DebugMode}}
{{#AutoFormat}}
{{var test = "Test"}}
{{var expression = (1 == 1 & 1 > 0)}}
{{var func = @Truncate("Hello", 3)}}
The code above would produce something similar to the following:
Debug Information
-----------------
Render Time: 1 milliseconds
Properties
----------
Message: Hello World
Names: System.String[]
Success: True
Variables
---------
test: Test
expression: 1 == 1 & 1 > 0
func: Hel