Suave.DotLiquid

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 = choose [ GET >=> choose [ path "/" >=> page "my_page.liquid" o ]]

Then, for your template:

<html> <head> <title></title> </head> <body> <p>Hello from !</p> </body> </html>

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 '{{model.name}}'. You can change the naming convention to C#:

DotLiquid.setCSharpNamingConvention()

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


<div> {% if model.UserName %} Hello {% else %} Dave is not here {% endif %} </div>

Example 2:

let model = Some "Dave" // or let model : string option = None let home = page "Index.html" model


<div> {% if model %} Hello {% else %} Dave is not here {% endif %} </div>

References

namespace Suave
Multiple items
module Model

from Suave

--------------------
type Model =
  {title: string;}

Full name: temp.Model
Model.title: string
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val o : Model

Full name: temp.o
val app : WebPart<HttpContext>

Full name: temp.app
val choose : options:WebPart<'a> list -> WebPart<'a>

Full name: Suave.WebPart.choose
union case HttpMethod.GET: HttpMethod
val path : pathAfterDomain:string -> WebPart

Full name: Suave.Filters.path
type UserModel =
  {UserName: string option;}

Full name: temp.UserModel
UserModel.UserName: string option
type 'T option = Option<'T>

Full name: Microsoft.FSharp.Core.option<_>
val model : UserModel

Full name: temp.model
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
val home : obj

Full name: temp.home
val model : string option

Full name: temp.model

results matching ""

    No results matching ""