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.
Copyright © 2021 Jogjafile Inc.
 
                        
hamletyields QuasiQuoters that are evaluated toblazeexpressions. UsingText.Blaze.Html.Renderer.String.renderHtmlyou can render them to a string.Let's start with a simple non-HTML example:
For increased efficiency, you could also use
Textinstead ofStringText.Blaze.Html.Renderer.Text.renderHtmlWriting this to a file is not different from the standard Haskell approach. You can do this, for example, by using
writeFileinstead 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.htmlnow contains a statically rendered greeting HTML.