[stringtemplate basics lesson is pretty good thomashartman1@gmail.com**20080910141956] move ./templates/favoriteAnimal.st ./templates/leastFavoriteAnimal.st hunk ./src/Controller.hs 31 - tutorial ++ simpleHandlers ++ usingTemplatesHandlers ++ staticfiles + tutorial ++ simpleHandlers ++ [ myFavoriteAnimal ] ++ staticfiles hunk ./src/ControllerBasic.hs 130 -usingTemplatesHandlers :: [ServerPartT IO Response] -usingTemplatesHandlers = [ +myFavoriteAnimal :: ServerPartT IO Response +myFavoriteAnimal = hunk ./src/ControllerBasic.hs 134 - (liftIO $ return . toResponse . HtmlString - =<< do templates <- directoryGroup "templates" - return $ renderTemplateGroup templates [("favoriteAnimal", "giraffe")] "my-favorite-animal" ) ] - ] + liftIO $ do templates <- directoryGroup "templates" + return . toResponse . HtmlString . + renderTemplateGroup templates [("favoriteAnimal", "Tyrannasaurus Rex") + , ("leastFavoriteAnimal","Bambi")] + $ "my-favorite-animal" + ] + hunk ./templates/leastFavoriteAnimal.st 1 -Again, my favorite animal is a $ favoriteAnimal $. (set in another template, favoriteAnimal.st) + + +

*********** My least favorite animal is $ leastFavoriteAnimal $. + +

*********** (set in another template, leastFavoriteAnimal.st) + +

*********** Notice that this template file uses CamelCase rather than dashes to separate words. + Otherwise there's an error with included templates. + So, in general: avoid template file names with dashes or underscores, and just use CamelCase for templates. + hunk ./templates/my-favorite-animal.st 2 - This is written in the top container template of my homepage, myhomepage.st. -

- It is generated using HStringTemplate. -

hunk ./templates/my-favorite-animal.st 4 - $ favoriteAnimal() $ + $ leastFavoriteAnimal() $ hunk ./templates/my-favorite-animal.st 8 - More Favorite Animals - hunk ./templates/my-favorite-animal.st 9 - - hunk ./templates/stringtemplate-basics.st 2 -

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/stringtemplate-basics.st 3 -

my favorite animal +

In the previous section we rendered a template in ghci using the following command hunk ./templates/stringtemplate-basics.st 5 +

*Main Misc View Text.StringTemplate> do templates <- directoryGroup "templates" ; writeFile "output.html" ( renderTemplateGroup templates [] "templates-dont-repeat-yourself" ) hunk ./templates/stringtemplate-basics.st 7 +

Let's look more carefully at these functions. hunk ./templates/stringtemplate-basics.st 9 -$! without headers or table of contents or any variables set, !$ - -

- - -

Note: hunk ./templates/stringtemplate-basics.st 22 +

Next, let's look at a slightly more involved example of StringTemplate usage than we've seen so far. hunk ./templates/stringtemplate-basics.st 24 +

hunk ./templates/stringtemplate-basics.st 35 +

Try to gain an understanding of the most important features in the StringTemplate system + by getting a sense of how the my-favorite-animal page got generated.

+ +

When you're done doing that, you should have enough StringTemplate knowledge to shoot yourself in the foot :) + +

For a more in depth look at StringTemplate, see the following: + +

hunk ./templates/templates-dont-repeat-yourself.st 33 -
*Main Misc View Text.StringTemplate> do templates <- directoryGroup "templates" ; writeFile "output.html" ( renderTemplateGroup templates [] "templates-dont-repeat-yourself" ) +
*Main Misc View Text.StringTemplate> do templates <- directoryGroup "templates" ; writeFile "output.html" \$ renderTemplateGroup templates [] "templates-dont-repeat-yourself" hunk ./templates/templates-dont-repeat-yourself.st 39 -

*Main Misc View Text.StringTemplate> do templates <- directoryGroup "templates" ; writeFile "output.html" ( renderTemplateGroup templates [("loggedInUser","DarthVader")] "templates-dont-repeat-yourself" ) +

*Main Misc View Text.StringTemplate> do templates <- directoryGroup "templates" ; writeFile "output.html" \$ renderTemplateGroup templates [("loggedInUser","DarthVader")] "templates-dont-repeat-yourself" hunk ./templates/templates-dont-repeat-yourself.st 47 -

You're missing the header image and css because you're opening a plain html file +

If you reload output.htlm, you'll see you are missing the header image and css because you're opening a plain html file