Skip to content

Templates

Ian Johnson edited this page Oct 29, 2022 · 5 revisions

Hardened provides it's own templating language that is inspired by mustache but compiled to C#.

Example template

{{model Hardened.IntegrationTests.Web.Lambda.SUT.Models.PersonListModel}}
{{using Hardened.IntegrationTests.Web.Lambda.SUT.Templates}}
<table>
    <tr><th>id</th><th>time</th><th>First Name</th><th>Last Name</th></tr>
    {{~#each Entries}}
    <tr><td class="{{/Css.Table}}" id="id{{ Id }}">{{ Id }}</td><td>{{$CustomToken}}</td><td>{{ FirstName }}</td><td>{{ LastName }}</td></tr>
    {{~/each}}
</table>
<script>
    window._u(() => console.log("got here"));
</script>

{{ model namespace.model }}

Templates should start with a model tag. This specifies the model type

{{ using namespace }}

Add namespace to template csharp file

{{ inject type variableName }}

inject service from IServiceProvider into template variable

{{ property }}

Output property

{{ #each IEnumerable }}

Loop through IEnumerable executing template foreach instance

{{ #if }}

If block used to control flow logic, can be paired with an else or else if

{{ $CustomToken }}

Execute custom token

{{ ^Raw CSharp }}

output raw csharp

{{ >subTemplate Model }}

Render sub template using Model as input.

Clone this wiki locally