gpt4 book ai didi

haskell - 在没有 Yesod 的情况下在 Haskell 中使用 Hamlet

转载 作者:行者123 更新时间:2023-12-04 01:47:40 26 4
gpt4 key购买 nike

谁能指出我如何在没有 Yesod 的情况下使用 Hamlet 的示例? http://www.yesodweb.com/book/templates是一个很棒的文档,但我无法让我的 ghci session 在不崩溃的情况下渲染一个简单的小村庄模板。

最佳答案

这是一个显示大部分基本内容的示例,包括呈现键入的 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

输出:
<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>

关于haskell - 在没有 Yesod 的情况下在 Haskell 中使用 Hamlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6712974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com