28

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.

Ionuț G. Stan
  • 176,118
  • 18
  • 189
  • 202
  • 1
    Not necessarily. This was for a little project that generates Kindle-compatible .mobi files (incidentally they're HTML and XML files). But I have other uses cases where a structured markup language is not involved. – Ionuț G. Stan Apr 25 '11 at 09:00

5 Answers5

32

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
Simon Michael
  • 2,278
  • 1
  • 18
  • 21
25

According to the Hackage popularity statistics, the top three packages, by far, are (2014):

  1. (29,000 downloads) shakespeare -- replacement for hamlet.
  2. (27,816 downloads) hamlet -- yesod framework templating
  3. (10,625 downloads) heist -- snap framework templating
  4. (7099 downloads) HStringTemplate -- general purpose templating

You can see more about these two systems in this question.

Community
  • 1
  • 1
Don Stewart
  • 137,316
  • 36
  • 365
  • 468
3

interpolatedstring-perl6 provides a simple and well designed Quasiquoter to produce interpolated String/Text from Templates containing arbitrary Haskell expressions.

Johannes Gerer
  • 25,508
  • 5
  • 29
  • 35
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.

gatoatigrado
  • 16,580
  • 18
  • 81
  • 143
1

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”.

firegurafiku
  • 3,017
  • 1
  • 28
  • 37
  • 1
    Just thought I'd mention that karver [uses partial functions for error handling](https://github.com/sourrust/karver/issues/7), so it is unsuitable for use cases where users input the templates. – Andrew Thaddeus Martin Jun 03 '15 at 12:45