开发者

Using html files as templates in happstack

I can find plenty of documentati开发者_如何学Con on using blitz and other compiletime templating libraries with happstack but I would like to know how to use html files as templates.


Though there are many options, my favourite would be Heist, which would allow you to define a splice:

> factSplice :: (Monad m) => TemplateMonad m Template
> factSplice = do
>   input <- getParamNode
>   let text = T.unpack $ X.nodeText input
>       n    = read text :: Int
>   return [X.TextNode $ T.pack $ show $ product [1..n]]
>

which could be used in a dynamic (loaded at runtime) HTML template:

<html>
  <head>
    <title>Factorial Page</title>
  </head>
  <body>
    <h1>Factorial Page</h1>
    <p>The factorial of 6 is <fact>6</fact></p>
  </body>
</html>

To use heist in happstack, you'll need the happstack-heist package. For more detail and other options, see Using Heist.


The HStringTemplate package provides a very general runtime templating system for not only HTML, but any sort of text output:

http://hackage.haskell.org/packages/archive/HStringTemplate/0.6.6/doc/html/Text-StringTemplate.html

The HStringTemplate package integrates with Happstack nicely through a few extra instances provided by an optional package: http://hackage.haskell.org/package/happstack-hstringtemplate

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜