forked from grumpydev/SuperSimpleViewEngine
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
Super Simple View Engine | ||
======================== | ||
|
||
A super simple regex based view engine used in [Nancy](https://github.com/thecodejunkie/Nancy) and (soon to be) [TinyTemplates](https://github.com/grumpydev/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] paraneter 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['<template name>'[, 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. | ||
Super Simple View Engine | ||
======================== | ||
|
||
A super simple regex based view engine used in [Nancy](https://github.com/thecodejunkie/Nancy) and (soon to be) [TinyTemplates](https://github.com/grumpydev/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] paraneter 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['<template name>'[, 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. |