Repository navigation
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>
Templates should start with a model tag. This specifies the model type
Add namespace to template csharp file
inject service from IServiceProvider into template variable
Output property
Loop through IEnumerable executing template foreach instance
If block used to control flow logic, can be paired with an else or else if
Execute custom token
output raw csharp
Render sub template using Model as input.