Revision as of 12:23, 1 July 2009
HStringTemplate is a Haskell-ish port of the Java StringTemplate library written by Terrence Parr. It can be used for any templating purpose, but is often used for dynamically generated web pages.
This is a stub page, which aims to supplement the API docs with tutorial style documentation.
1 Getting started
Assuming you have installed the library, try the following at a GHCi prompt:
Prelude> :m + Text.StringTemplate Prelude Text.StringTemplate> let t = newSTMP "Hello $name$" :: StringTemplate String
This has created a 'String' based StringTemplate. StringTemplates can be based around any 'Stringable' type, allowing you to use ByteString's or any other type if you write the Stringable instance. The template has a single 'hole' in it called 'name', delimited by dollar signs.
We can now fill in the hole using 'setAttribute', and render it to its base type (String in this case):
Prelude Text.StringTemplate> render $ setAttribute "name" "Joe" t "Hello Joe"
Instead of "Joe", we can use anything that has a ToSElem instance