How can I use the hamlet
framework to generate static HTML pages from inside Haskell?
Note: This question intentionally doesn't show research effort. For my research effort, see the Q&A-style answer below.
How can I use the hamlet
framework to generate static HTML pages from inside Haskell?
Note: This question intentionally doesn't show research effort. For my research effort, see the Q&A-style answer below.
hamlet
yields QuasiQuoters that are evaluated toblaze
expressions. UsingText.Blaze.Html.Renderer.String.renderHtml
you can render them to a string.Let's start with a simple non-HTML example:
For increased efficiency, you could also use
Text
instead ofString
Text.Blaze.Html.Renderer.Text.renderHtml
Writing this to a file is not different from the standard Haskell approach. You can do this, for example, by using
writeFile
instead ofputStrLn
. You only need to modify the last lineNow we only need to add HTML markup instead of using plain text. See the Shakespeare documentation for further reference.
greet.html
now contains a statically rendered greeting HTML.