Skip to content

Super simple regex based view engine used in Nancy diagnostics and (soon to be) TinyTemplates.

Notifications You must be signed in to change notification settings

grumpydev/SuperSimpleViewEngine

Repository files navigation

Super Simple View Engine

A super simple regex based view engine used in Nancy and (soon to be) TinyTemplates.

Models can either be standard types, or ExpandoObjects (or any other object implementing IDynamicMetaObjectProvider that implements IDictionary<string, object> to access its properties).

Syntax

All commands have an optional semi-colon delimiter which can be used to remove ambiguity. Any [.Parameters] parameter can be multiple levels deep (e.g. This.Property.That.Property).

Standard variable substitution

Syntax: @Model[.Parameters] Example: Hello @Model.Name Example: Hello @Model.User.Age

Replaces with the string representation of the parameter, or the model itself if a parameter is not specified.

Iterators

Syntax: @Each[.Parameters] [@Current[.Parameters]] @EndEach Example: @Each.Users Hello @Current! @EndEach

Creates one copy of the contents of the @Each per element in the collection and substitutes @Current in the same way as @Model, but bound to the current item in the collection.

@Current can be used multiple times inside the @Each block.

Conditionals

Syntax: @If[Not].Parameters [contents] @EndIf Example: @If.HasUsers Users found! @EndIf Example: @IfNot.HasUsers No users found! @EndIf

Parameters must be a boolean (see Implicit Conditionals below). Nesting of @If and @IfNot statements is not supported.

Implicit Conditionals

If the model has property that implements ICollection then you can use an implicit conditional. The implicit conditional syntax is the same as a normal conditional, but the Parameters part is set to "Has[CollectionPropertyName]". The conditional will be true if the collection contains items, and false if it does not or if it is null.

Example: @If.HasUsers Users found! @EndIf

The above example will expand to "Users found!" if the model has a collection called "Users" and it contains items.

HTML Encoding

Both the @Model and @Current keywords (with or without parameters) can have an optional ! after the @ to HTML encode the output.

Example: @!Model.Test

Would HTML encode the output.

Partials

Syntax: @Partial[''[, Model.Property]]

Example: @Partial['subview.sshtml']; (Renders the partial view with the same model as the parent)

Example: @Partial['subview.sshtml', Model.User]; (Renders the partial view using the User as the model)

Renders a partial view. A property of the current model can be specified to be used as the partial view's model, or it may be omitted to use the current view's model instead.

About

Super simple regex based view engine used in Nancy diagnostics and (soon to be) TinyTemplates.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages