Skip to main content

Rendering

Choose fragment or document rendering deliberately and render each completed view at the application boundary.

On this page

Overview

Choose fragment or document rendering deliberately and render each completed view at the application boundary.

Fragments

Render.toString serializes exactly the supplied element and does not prepend a doctype.

let fragment =
    div { _class "notice"; "Saved" }
    |> Render.toString
// <div class="notice">Saved</div>

Documents

Render.toHtmlDocString prepends <!DOCTYPE html> and is intended for a complete HTML document.

let responseBody =
    html {
        _lang "en"
        head { title "Account" }
        body { main { h1 { "Account" } } }
    }
    |> Render.toHtmlDocString

Application boundaries

FSharp.ViewEngine has no web-framework dependency. Pass the resulting string to your framework's normal HTML response API. See the Giraffe integration for a complete server example.