[Haskell-cafe] HStringTemplate to generate html tables

Thomas Hartman tphyahoo at gmail.com
Thu Sep 18 12:10:19 EDT 2008

I am trying to use HStringTemplate for generating html tables, for use
in http://happstutorial.com:5001

The best I could do is below. Seems awfully kludgy.

Can someone suggest a better way, which keeps me inside the
StringTemplate way of doing things? (Eg, no suggestions to use HTML.*
libraries, which are nice for some things but are a higher barrier to
entry than just jumping in and writing html.)

Some kind of map structure... for each... ?

Thanks for any help!


{-# LANGUAGE NoMonomorphismRestriction #-}
import Text.StringTemplate
import Control.Applicative
import qualified Text.PrettyPrint as PP

main = putStrLn . PP.render . toPPDoc $ tableFromCells cells
cells = [["mee","mah","moh"],["fee","fah","foh"]]

-- This does generate an html table, but seems horribly obfuscated.
-- is there machinery for doing things like html table generation
-- in some better way than this hack where </end><start>
-- tags are used as a separator?
-- I would imagine something like
-- newSTMP "$cells:{<td>$it$</td>}:{<tr>$it</tr>}:{<table>$it</table>}"
-- which works a bit like a list comprehension
tableFromCells cells = setAttribute "cells" cells . optInsertTmpl
  $ newSTMP "$cells:\

More information about the Haskell-Cafe mailing list