{-# OPTIONS -XPatternSignatures #-} module ControllerUsingTemplates where import HAppS.Server import Misc import Data.Monoid import View import Text.StringTemplate usingTemplatesHandlers :: [ServerPartT IO Response] usingTemplatesHandlers = debugFilter [ dir "usingtemplates" [ exactdir "/testtgio" [ ioMsgToSp ( withTutTemplate $ renderDef [("favoriteAnimal", "giraffe")] "myhomepage" ) ] ] ] -- generate some html, from templates in templates directory {- generatePages = do -- should probably change this to directoryGroup or directoryGroupLazy in production code -- but not sure which one is better... figure it out later. (tg :: STGroup String) <- unsafeVolatileDirectoryGroup "templates" 1 -- 1 second reload time (writeFile "myHomepage.html" . genMyHomepage) tg (writeFile "moreFavoriteAnimals.html" . genMoreFavoriteAnimals) tg where genMyHomepage = toString . setAttribute "favoriteAnimal" "giraffe" . (getStringTemplateDef "myhomepage") genMoreFavoriteAnimals = toString . optInsertTmpl [("separator","

\n")] . setAttribute "favoriteAnimals" favoriteAnimals . getStringTemplateDef "moreFavoriteAnimals" favoriteAnimals = ["guppies","mayflies","dinosaurs"] -}