首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Scotty + Html ->如何将它们交织起来?

Scotty + Html ->如何将它们交织起来?
EN

Stack Overflow用户
提问于 2016-02-24 02:29:19
回答 1查看 349关注 0票数 1

如何在Scotty中使用html页面(,包括 html模板)?但不是通过Blaze,因为我不喜欢用haskell代码描述它的结构。它认为我应该抢劫,但如何确切地把它与斯科蒂交织在一起?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-24 09:02:34

您可以使用Heist.renderTemplate将一个模板转换为Blaze.ByteString.Builder.Builder (我认为这不是blaze html,我认为没关系),然后通过Web.Scotty.raw设置。例如:

代码语言:javascript
复制
{-# LANGUAGE OverloadedStrings #-}
import Heist
import Heist.Interpreted

import Web.Scotty (scotty, get, raw, setHeader)

import Control.Monad.Trans.Either (runEitherT)
import Control.Monad.IO.Class (liftIO)
import Blaze.ByteString.Builder (toByteString)

import qualified Data.ByteString.Lazy as DBL
import qualified Data.Text.Lazy.Encoding as DT

import Text.XmlHtml

main = scotty 3000 $
    get "/" $ do
        -- normally you would probably load your templates from a file,
        -- but to keep the example small
        (Right heist) <- liftIO $ runEitherT $ initHeist emptyHeistConfig
        let heist' = addTemplate "foo" [TextNode "Hello world!"] Nothing heist

        (Just (builder, mime)) <- renderTemplate heist' "foo"

        setHeader "Content-Type" (DT.decodeUtf8 $ DBL.fromStrict mime)
        raw $ DBL.fromStrict $ toByteString builder
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35592164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档