[working on stringtemplate basics thomashartman1@gmail.com**20080920095425] hunk ./src/ControllerBasic.hs 135 - return . toResponse . HtmlString . + let r = renderTemplateGroup templates [("favoriteAnimal", "Tyrannasaurus Rex") + , ("leastFavoriteAnimal","Bambi") + -- if you set the same template variable several times it + -- gets repeated when it gets displayed + -- I think this is reasonable, because it gives you + -- feedback that there's probably a bug in your program + , ("favoritePlant","Ficus") + , ("favoritePlant","Wheat") + , ("favoritePlant","Sugarcane")] + $ "myFavoriteAnimalBase" + return . toResponse . HtmlString $ r hunk ./src/ControllerBasic.hs 147 - renderTemplateGroup templates [("favoriteAnimal", "Tyrannasaurus Rex") - , ("favoriteAnimal", "Tyrannasaurus Rexall") - , ("leastFavoriteAnimal","Bambi")] - $ "my-favorite-animal" + hunk ./src/Misc.hs 61 -renderTemplateGroup gr attrs tmpl = - toString $ - maybe ( error $ "template not found: " ++ tmpl ) - ( setManyAttrib {-. clean -} $ attrs ) +renderTemplateGroup gr attrs tmpl = do + maybe ( "template not found: " ++ tmpl ) + ( toString . setManyAttrib attrs ) hunk ./templates/my-favorite-animal.st 1 - - My favorite animal is a: $ favoriteAnimal $ (set with setAttribute) -

- $ leastFavoriteAnimal() $ -

- If I forget to set an attribute (favoriteMammal), it just doesn't display: $ favoriteMammal $ -

-

You can comment out parts of a template: $! This Won't Display !$ - - rmfile ./templates/my-favorite-animal.st addfile ./templates/myFavoriteAnimal.st hunk ./templates/myFavoriteAnimal.st 1 + My favorite animal is a: $ favoriteAnimal $ (set with setAttribute) +

+ $ leastFavoriteAnimal() $ +

+ If I forget to set an attribute (favoriteMammal), it just doesn't display: $ favoriteMammal $ +

+ If I set the same attribute several times, it just shows up repeated. + I think this is reasonable, because it gives you feedback that there's probably a bug in your program: +

+ Favorite plant: $ favoritePlant $ +

+ You can comment out parts of a template: $! This Won't Display !$ +

You can display lists: $ favoriteMinerals $ +

Remember this: Don't use any kind of punctuation (eg hyphens, underscore) in template names. +
To separate words, use CamelCase. +
Punctuation screws up the including mechanism. +
Try uncommenting the next line and see what you get: + $!

Include least-favorite-animal.st: $ least-favorite-animal.st $ !$ + + addfile ./templates/myFavoriteAnimalBase.st hunk ./templates/myFavoriteAnimalBase.st 1 + + $! This is a comment. The next line is an included template. Look at templates/my-favorite-animal.st !$ + $ myFavoriteAnimal() $ + hunk ./templates/stringtemplate-basics.st 29 - \$ "my-favorite-animal" + \$ "myFavoriteAnimalBase" hunk ./templates/stringtemplate-basics.st 31 -

  • The template: templates/my-favorite-animal.st -
  • An included template: leastFavoriteAnimal() +
  • The template: templates/myFavoriteAnimalBase.st +
  • A template included from inside an included templates: + leastFavoriteAnimal()