这是我的代码:
testSplice :: C.Splice Handler
testSplice = return $ C.yieldRuntimeText $ do
return "中文"
我将它绑定到一个标签:
splices :: Splices (C.Splice Handler)
splices =
"testSplice" ## testSplice
并在 layout.tpl 上使用它:
<meta charset="UTF-8">
<testSplice/>
浏览器上的输出是
-�
我做错了什么?
抱歉耽搁了,我忙了一段时间,现在我回来了,我想我可能没有把问题说得足够具体@mightybyte这是出现问题的代码,我希望它会使问题更加说明:
测试.hs:
{-# LANGUAGE OverloadedStrings #-}
import Snap
import Heist
import qualified Heist.Compiled as C
import Data.Monoid
import Control.Monad.Trans.Either
import Data.Maybe
main :: IO ()
main = quickHttpServe site
site :: Snap ()
site =
route [("/", testSnap)]
testSnap :: Snap ()
testSnap = do
hs <- liftIO $ load "template" splices
let runtime = fromJust $ C.renderTemplate hs "test"
builder <-liftIO (fst runtime)
writeBuilder builder
where
splices :: Splices (C.Splice IO)
splices =
"testSplice" ## testSplice
load :: MonadIO n
=> FilePath
-> Splices (C.Splice n)
-> IO (HeistState n)
load baseDir splices = do
tmap <- runEitherT $ do
let t = loadTemplates baseDir
hc = HeistConfig
defaultInterpretedSplices
defaultLoadTimeSplices
splices
mempty
[t]
initHeist hc
either (error . concat) return tmap
testSplice :: C.Splice IO
testSplice = return $ C.yieldRuntimeText $ do return "中文"
模板/test.tpl
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<testSplice/>
</body>
</html>
现在我尝试了 heist-0.13.0.2,它现在工作正常,Daniel 干得好!