Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 984 Bytes

TypeProvider.md

File metadata and controls

55 lines (43 loc) · 984 Bytes

Trulla Templates

NuGet Badge

#r "nuget: Trulla"

open Trulla

let [<Literal>] TestTemplate = """
Hello {{user.name}}, how are you?

Your Orders
===
{{for order in orders|---}}
ID: {{order.id}}
({{if order.isActive}}active{{else}}inactive{{end}})
{{end}}
    """

// All types required by the given template
// are infered and provided:
type Tmpl = Template<TestTemplate>

// Instanciate a typed model for the tempalte.
let templateModel =
    Tmpl.Root(
        [
            Tmpl.order("Order 1", false)
            Tmpl.order("Order 2", true)
            Tmpl.order("Order 3", false)
        ],
        Tmpl.user("Hans"))

// Render and print it:
Tmpl.Render(templateModel) |> printfn "%s"

This will print:

Hello Hans, how are you?

Your Orders
===

ID: Order 1
(inactive)
---
ID: Order 2
(active)
---
ID: Order 3
(inactive)