[begin on hstringtemplates-basics thomashartman1@gmail.com**20080910095844] hunk ./src/ControllerBasic.hs 131 - dir "usingtemplates" - [ exactdir "/testtgio" - [ ioMsgToSp ( return . HtmlString =<< renderTemplateDir "templates" [("favoriteAnimal", "giraffe")] "myhomepage" ) ] - ] + exactdir "/usingtemplates/my-favorite-animal" + [ ServerPartT $ \rq -> + (liftIO $ return . toResponse . HtmlString + =<< renderTemplateDir "templates" [("favoriteAnimal", "giraffe")] "my-favorite-animal" ) ] hunk ./src/ControllerBasic.hs 136 + hunk ./src/Misc.hs 59 - hunk ./src/View.hs 18 - let rendertut = renderTemplateDir "templates" + rendertut = renderTemplateDir "templates" hunk ./src/View.hs 70 + , "hstringtemplate-basics" hunk ./src/View.hs 72 + addfile ./templates/hstringtemplate-basics.st hunk ./templates/hstringtemplate-basics.st 1 +

HStringTemplate Basics

+

Follow the links below by clicking on them. +Each "page" link is paired with one or more "code" or "template" links that you should also follow. +Try to match what is happening in the page link with what went on behind the scenes in the code and template links.

+ +

my favorite animal + + + + + +

Now, load up ghci by running ./hackInGhci

+ +

If you are running this tutorial locally, you can see the effect of +rendering the above content pane by calling

*Main> +renderTemplateDir "templates" [] "templates-dont-repeat-yourself" +

and watching it squirt out html.

It's not too much fun to +develop this way, so the next thing you might want to try is actually +modifying the current template (in +./templates/templates-dont-repeat-yourself.st) with some random text, +reloading the page, and watching your changes appear. + +$! without headers or table of contents or any variables set, !$ + +

+ + addfile ./templates/my-favorite-animal.st hunk ./templates/my-favorite-animal.st 1 + + This is written in the top container template of my homepage, myhomepage.st. +

+ It is generated using HStringTemplate. +

+ My favorite animal is a: $ favoriteAnimal $ (set with setAttribute) +

+ $ favoriteAnimal() $ +

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

+ More Favorite Animals + +

You can comment out parts of a template: $! This Won't Display !$ + + + + hunk ./templates/myhomepage.st 1 - - This is written in the top container template of my homepage, myhomepage.st. -

- It is generated using HStringTemplate. -

- My favorite animal is a: $ favoriteAnimal $ (set with setAttribute) -

- $ favoriteAnimal() $ -

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

- More Favorite Animals - rmfile ./templates/myhomepage.st hunk ./templates/tableofcontents.st 3 -

  • happs intro -
  • prerequisites +
  • happs intro +
  • prerequisites hunk ./templates/tableofcontents.st 10 +
  • hstringtemplate basics + hunk ./templates/templates-dont-repeat-yourself.st 18 -$! next example should vary the text around the name !$ - hunk ./templates/templates-dont-repeat-yourself.st 22 +

    You might have also noticed that the table of contents-style navigation links in the left pane +change colors depending on what page is selected. You could have a look at the the +/templates/tableofcontents.st to get another taste of how templating works. hunk ./templates/templates-dont-repeat-yourself.st 26 -

    hunk ./templates/templates-dont-repeat-yourself.st 27 -

    HAppS doesn't care much what templating system you use. -I use the TK HStringTemplate package to get the job done.

    hunk ./templates/templates-dont-repeat-yourself.st 29 +

    HAppS doesn't care much what templating system you use. +I use the TK HStringTemplate package to get the job done, so that's the syntax you're seeing. +We'll learn some HStringTemplate basics next. +

    + hunk ./templates/templates-dont-repeat-yourself.st 35 -

    Follow the links below by clicking on them. -Each "page" link is paired with one or more "code" or "template" links that you should also follow. -Try to match what is happening in the page link with what went on behind the scenes in the code and template links.

    hunk ./templates/templates-dont-repeat-yourself.st 36 -