Suave is a simple web development F# library providing a lightweight web server and a set of combinators to manipulate route flow and task composition.

Download this project as a .zip file Download this project as a tar.gz file
View on GitHub


Installing DotLiquid

paket add nuget DotLiquid
paket add nuget Suave.DotLiquid

How to use liquid from Suave.

open Suave
open Suave.DotLiquid
open DotLiquid

type Model =
  { title : string }

setTemplatesDirectory "./templates"

let o = { title = "Hello World" }

let app =
    [ GET >=> choose
        [ path "/" >=> page "my_page.liquid" o ]]

Then, for your template:

    <title>{{ model.title }}</title>
    <p>Hello from {{ model.title }}!</p>

Naming conventions

Suave.DotLiquid sets the DotLiquid naming convention to Ruby by default. This means that if, for example, your model is a record type with a member called ‘Name’, DotLiquid would expect the binding to be ‘{{}}’. You can change the naming convention to C#:


Working with Options

DotLiquid can handle option types.

Example 1:

type UserModel = {
    UserName: string option

let model = { UserName = Some "Dave" }
// or
let model = { UserName = None }

let home = page "Index.html" model
    {% if model.UserName %}
        Hello {{model.UserName.Value}}
    {% else %}
        Dave is not here
    {% endif %}

Example 2:

let model = Some "Dave"
// or
let model : string option = None

let home = page "Index.html" model
    {% if model %}
        Hello {{model.Value}}
    {% else %}
        Dave is not here
    {% endif %}