The Super Simple View Engine

Nathan Armstrong edited this page Apr 6, 2017 · 13 revisions

The Super Simple View Engine, also known as SSVE, is a regex (the implementation uses regular expressions to perform substitutions) based view engine that was designed to support simple templating scenarios, so a lot of the features you see in other engines may not be available.

There is no need to install a separate Nuget to use the engine as it is embedded into the main Nancy assembly, and will automatically be wired up and ready to use in your application. The engine handles views with either sshtml, html or htm file extensions.

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

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).

As SSVE is a regular expression based view engine there is no “code execution”, so you cannot specify an arbitrary chunk of your own code to execute. The built in syntax/commands that you can use are as follows.

Please note that all quotes should be single-quotes in the expressions

Standard variable substitution

Replaces with the string representation of the parameter, or the model itself if a parameter is not specified. If the substitution can not be performed, for instance if you specify an invalid model property, it will be substituted with [Err!]




Hello @Model.Name, your age is @Model.User.Age


Enables you to iterate over models that are collection. Iterators cannot be nested



@Each will implicitly be associated with the model and for each iteration the @Current will represent the current item in the collection. @Current can be used multiple times in the iterator block, and is accessed in the same way as @Model.


   Hello @Current.Name!


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




   No users found!

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 can have a Has-prefix. The conditional will be true if the collection contains items, and false if it does not or if it is null.




   Users found!

The above example will expand to "Users found!" if the model has a collection called Users and it contains items; if the collection is empty then the text would not be displayed.

HTML Encoding

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







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. The file extension of the view is optional.


@Partial['<view name>'[, Model.Property]]


// Renders the partial view with the same model as the parent

// Renders the partial view using the User as the model
@Partial['subview.sshtml', Model.User];

Master pages and sections

You can put shared layout in a master page and declare content sections that will be populated by the views. It is possible to have nested master pages and you are not obligated to provide content for all of the content sections.

The master pages will have access to the @Model of the view and the file extension is optional when specifying the name of the master to use in your view.

You can use the @Section tag multiple times and is used to both declare a content section, in a master page, and to define the content blocks of a view.





// master.sshtml

// index.sshtml

   This is content on the index page

Anti-forgery token

Renders an anti-forgery token, on the page, in an hidden input to prevent cross-site request forgery attacks. The token will automatically be validated when a new request is posted to the server (assuming CSRF protection hasn’t been turned off).





Path expansion

Expands a relative paths to a fully qualified URL.





Starting from v1.2, SSVE performs automatic path expansion in all HTML attributes (more specifically, in all name="value" pairs, both with single and double quotes around value) where attribute value starts with ~/. For example, <a href="@Path['~/relative/path']" ...> can be significantly shortened to <a href="~/relative/path" ...>.

Extending the SSVE

It is possible to extend the SSVE to support additional 'matchers' to meet your needs. This stackoverflow post gives an example of how to do this by describing how you could extend the SSVE to support text translation substitutions similar to the "@Text.TranslationKey" token support of the Razor View Engine.

« Part 10. View Engines  —  Documentation overview  —  Part 10. Razor »

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.