ExternalReality
ExternalReality

Reputation: 543

Generate Html List in Snap

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?

Upvotes: 2

Views: 449

Answers (1)

Antoine Latter
Antoine Latter

Reputation: 1555

If you want to stick with a Heist splice, the function renderHtmlNodes from the Text.Blaze.Renderer.XmlHtml module 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:

numbers :: Int -> Splice AppHandler
numbers n = return $ renderHtmlNodes $ do
                    p "A list of natural numbers"
                    ul $ forM_ [1 .. n] (li .toHtml)

Upvotes: 3

Related Questions