谁能指点我一个如何使用没有Yesod的哈姆雷特的例子? http://www.yesodweb.com/book/templates是一个很好的文档,但我无法让我的ghci会话渲染一个简单的哈姆雷特模板而不会崩溃.
ham*_*mar 16
这是一个显示大多数基本内容的示例,包括呈现类型化URL.
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
import Data.Text
import Text.Blaze.Html.Renderer.String (renderHtml)
import Text.Hamlet hiding (renderHtml)
data Url = Haskell | Yesod
renderUrl Haskell _ = pack "http://haskell.org"
renderUrl Yesod _ = pack "http://www.yesodweb.com"
title = pack "This is in scope of the template below"
template :: HtmlUrl Url
template = [hamlet|
<html>
<head>
#{title}
<body>
<p>
<a href=@{Haskell}>Haskell
<a href=@{Yesod}>Yesod
|]
main = do
let html = template renderUrl
putStrLn $ renderHtml html
Run Code Online (Sandbox Code Playgroud)
输出:
<html><head>This is in scope of the template below</head>
<body><p><a href="http://haskell.org">Haskell</a>
<a href="http://www.yesodweb.com">Yesod</a>
</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)