To do this, you use a sendFilehandler in your function ( see its definition )
The first argument is the Mime type, and the second is the file path.
For example, you can encode something like:
getMyFileR :: Handler ()
getMyFileR = sendFile "text/html" "myfile.html"
Here is another example. Let's say I have the following model:
Resource
filename FilePath
mimetype ContentType
deriving Typeable
A handler might look like this:
resourceDirectory :: FilePath
resourceDirectory = "resource"
getResourceGetR :: ResourceId -> Handler ()
getResourceGetR resourceId = do
resource <- runDB $ get404 resourceId
sendFile (resourceMimetype resource)
(resourceDirectory </> unpack (resourceFilename resource))
Edit 2015-06-05
sendFileworks at a low level, addScriptor $(widgetFile …)works at a higher level.
$(widgetFile …) TemplateHaskell Hamlet/Cassius/Lucius/Julius Haskell . [hamlet|…|].
addScript Route, sendFile FilePath. , addScript . sendFile .
Html Hamlet:
addScript Html : addScript script, . Html .