\begin{code} {-# LANGUAGE QuasiQuotes #-} import Text.Hamlet import qualified Data.ByteString.Lazy as L data Person = Person { name :: String , age :: String , page :: PersonUrls , isMarried :: Bool , children :: [String] } data PersonUrls = Homepage | PersonPage String renderUrls :: PersonUrls -> [(String, String)] -> String renderUrls Homepage _ = "/" renderUrls (PersonPage name) _ = '/' : name footer :: Hamlet url footer = [$hamlet| #footer Thank you, come again |] template :: Person -> Hamlet PersonUrls template person = [$hamlet| !!! %html %head %title Hamlet Demo %body %h1 Information on $string.name.person$ %p $string.name.person$ is $string.age.person$ years old. %h2 $if isMarried.person Married $else Not married %ul $forall children.person child %li $string.child$ %p %a!href=@page.person@ See the page. ^footer^ |] main :: IO () main = do let person = Person { name = "Michael" , age = "twenty five & a half" , page = PersonPage "michael" , isMarried = True , children = ["Adam", "Ben", "Chris"] } L.putStrLn $ renderHamlet renderUrls $ template person \end{code} Outputs (new lines added for readability):
    <!DOCTYPE html>
    <html><head><title>Hamlet Demo</title></head><body>
    <h1>Information on Michael</h1>
    <p>Michael is twenty five & a half years old.</p>
    <h2>Married</h2>
    <ul><li>Adam</li><li>Ben</li><li>Chris</li></ul>
    <p><a href="/michael">See the page.</a></p>
    <div id="footer">Thank you, come again</div>
    </body></html>