How do I load a plain html-formatted file (not a hamlet-formatted file) as a widget? In other words I'm looking for the html equivalent of:
toWidget $(whamletFile "test.hamlet")
How do I load a plain html-formatted file (not a hamlet-formatted file) as a widget? In other words I'm looking for the html equivalent of:
toWidget $(whamletFile "test.hamlet")
For this you use
sendFile
in your handler function (see its definition)The first argument is the Mime Type while the second is the file path.
For example, you could code something like:
Here’s Another example. Say I have the following model:
The handler might look like:
Edit 2015-06-05
sendFile
operates at a low level whileaddScript
or$(widgetFile …)
operates at a higher level.$(widgetFile …)
uses TemplateHaskell to convert your Hamlet/Cassius/Lucius/Julius templates into actual Haskell source code before your project is compiled. The same applies similarly to[hamlet|…|]
.addScript
works with aRoute
whilesendFile
works with aFilePath
. This meansaddScript
will be able to detect missing files at compile time.sendFile
will detect missing files at runtime.There are some tools to convert Html to Hamlet:
An equivalent of
addScript
for Html files does not make sense:addScript
will generate ascript
tag to tell the browser to download an external resource. This does not apply to an Html file.