I want to integrate Snap’s templating and Blaze HTML builder by building some HTML and binding it to a tag for use in a Heist template. Here is what I have attempted.
numbers :: Int -> Splice AppHandler
numbers n = return $ [TextNode $ T.concat.toChunks.renderHtml $ do
p "A list of natural numbers"
ul $ forM_ [1 .. n] (li .toHtml)]
This does not work as intended since snap renders the HTML string directly to the generated page. How do I get snap to render blaze generated HTML?
If you want to stick with a Heist splice, the function
renderHtmlNodesfrom theText.Blaze.Renderer.XmlHtmlmodule in the xmlhtml package should help a lot in this case.Docs: http://hackage.haskell.org/packages/archive/xmlhtml/0.1.5.2/doc/html/Text-Blaze-Renderer-XmlHtml.html
I don’t fully understand your example, but this is how I would modify it to incorporate my suggestion: