问题
What are some preferred packages for templating in Haskell. Something similar to Django Templates, or PHP.
I don't want to always use it with HTML. It can be any other thing. I guess what I want is a string interpolation library, that also supports loops, registration of filter/escape utilities, if conditions, etc.
回答1:
According to the Hackage popularity statistics, the top three packages, by far, are (2014):
- (29,000 downloads) shakespeare -- replacement for hamlet.
- (27,816 downloads) hamlet -- yesod framework templating
- (10,625 downloads) heist -- snap framework templating
- (7099 downloads) HStringTemplate -- general purpose templating
You can see more about these two systems in this question.
回答2:
Some related packages:
- Bravo - Static text template generation library
- chunks - Simple template library with static safety
- halipeto - Haskell Static Web Page Generator
- hamlet - Haml-like template files that are compile-time checked
- hastache - Haskell implementation of Mustache templates
- heist - An xhtml templating system
- HStringTemplate - StringTemplate implementation in Haskell.
- Interpolation - Multiline strings, interpolation and templating.
- PCLT - Extension to Show: templating, catalogizing, languages, parameters, etc.
- press - Text template library targeted at the web / HTML generation
- template - Simple string substitution
- twine - very simple template language
回答3:
hastache seems rather well designed imo. Bravo is a cool idea, but suited for what I want (loops, etc.), and it assumes all parameters are, in some way or another, strings.
回答4:
interpolatedstring-perl6 provides a simple and well designed Quasiquoter to produce interpolated String/Text from Templates containing arbitrary Haskell expressions.
回答5:
There is also karver (github) package, not mentioned in other answers. Author says “its syntax is heavily inspired by Jinja2”, but “it isn't as full featured or production ready as Jinja is”.
来源:https://stackoverflow.com/questions/5770168/templating-packages-for-haskell