Like Yesod, so diving in deep. Have a question: using Yesod I can call eg. data type App
with Warp
(warp 3000 App
).
How can I serve up HTML created using Shakespeare templates (like below). Got this from Michael Snoyman's book.
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Text.Blaze.Html.Renderer.String (renderHtml)
import Text.Hamlet (HtmlUrl, hamlet)
import Data.Text (Text)
import Yesod
data WebRoutes = Home | Time | Stylesheet
render :: WebRoutes -> [(Text, Text)] -> Text
render Home _ = "/home"
render Time _ = "/time"
render Stylesheet _ = "/stylesheet"
template :: Text -> HtmlUrl WebRoutes
template title = [hamlet|
<html>
<head>
<title>#{varTitle}
<link rel=stylesheet href=@{Stylesheet}>
<body>
<h1 #headerId>#{title}
|]
varTitle :: String
varTitle = "Test outputd"
main :: IO ()
main = putStrLn $ renderHtml $ template "Test output" render