# Yesod web framework/View
### View

The Handler monad returns content in one or more of several formats as components of types that implement the HasReps class {RepHtml, RepJson, RepXml, RepPlain, the dual RepHtmlJson, a pair or list of pairs [(ContentType, Content)], ..}. Json examples:
The HasReps default implementation of chooseRep chooses the document representation to be returned according to the preferred content-type list of the client accept header.
Widgets are HTML DOM code snippets made by specific commands (e.g. setTitle) or from templates of structure (html) / behaviour (javascript) / style (css), whose types instantiate the classes ToWidget, ToWidgetHead or ToWidgetBody.
A Widget monad, based on a Writer one and argument to defaultLayout, facilitate to piece the widgets together.

#### Template interpolation - Shakespearean templates

See ref. These are content view templates that follow a common substitution pattern of code expressions within curly brackets with different character prefix to refer to

##### template expressions with ^{...}

    other templates of the same type as ^{template params},

##### route expressions with @{...}

    safe (typed) urls as @{HomeR},

##### message expressions with _{...}

    i18n message rendering as _{MsgMessage params}

##### other Haskell expressions with #{...}

    haskell expression rendering as #{haskell_expression} which type must be convertible
** in case of hamlet html templates, the expression type must be an instance of Text.Blaze.ToMarkup
** in case of css templates, the expression type must be an instance of Text.Cassius.ToCss
** in case of javascript templates, the expression type must be an instance of Text.Julius.ToJavascript
** in case of i18n message definitions (in "isoLang.msg" files) with parameter interpolations, the expression type must be an instance of Text.Shakespeare.I18N.ToMessage
** in case of plain text templates, the expression type must be an instance of Text.Shakespeare.Text.ToText
Using non-English text in expressions requires use of the Unicode-aware type Text, since GHC's show for the type String renders non-ASCII characters as escaped numerical codes.
* external file templates: Template content can be loaded from external files using compile time splice calls as $(expr).
* reload mode for external files: See doc.

##### Localizable (i18n) messages

See ref. For every supported language ISO name there should be a file in the messages subfolder as <iso-language>.msg with entries like
For each entry in en.msg a message constructor is generated, prefixing the message name by "Msg", so the example msg. can be referred as
Actual i18n support is missing from the stack app template. You have to add the mkMessage "MyApp" directory isoLangDefault to the "Foundation.hs" file to get the messages instantiated.

##### HTML-like templates

* the hamlet quasiquoter (a parser to compile-time Template Haskell code) specified in the T.H. Oxford brackets syntax [qq| ... |] introduces an indentation based structured html template with '$' prefixed lines of logic statements (See doc.). Automatic closing tags are generated only for the tag at line start position.
* the whamlet quasiquoter returns a Widget expression. (saves toWidget before [hamlet|..|]).

##### JavaScript templates

* the julius quasiquoter: introduces a javascript template. Javascript variants CoffeeScript and Roy-language have also specific quasiquoters.

##### CSS-like templates

* the cassius quasiquoter: introduces a css template with indentation based structuring.
* the lucius quasiquoter: introduces a css template with standard syntax plus shakespeare-template style substitutions.

##### Plain text templates

* for e-mail or text/plain http content type.
* templates: lt: lazy text, st: strict text
* templates for text with a left margin delimiter '|': lbt (lazy), sbt (strict)

#### Specific views

* Search engines XML Sitemaps, where sitemap returns an XML Sitemap as http response, with the routes we want the search engines to crawl, and attributes to instruct the crawler, from a provided list of SitemapUrl records.
* Navigation Breadcrumbs. You have to provide a YesodBreadcrumbs instance for the site where the generator function breadcrumb should return a title and parent route for each one. Then, the query function breadcrumbs will return the present route title and ancestors' (route, title) pairs.
* Web feed views (RSS / Atom). You have handlers that return RepRss, RepAtom, or dual RepAtomRss content (to be selected on accept headers' preferred content-type list) from a given Feed structure.

## References

* 1 2 "The class HasReps". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "RESTful Content". Yesodweb.com. Retrieved 2012-10-23.
* ↑ "The class ToContent". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "More Client Side Yesod: todo sample". Yesodweb.com. 2012-04-23. Retrieved 2012-10-23.
* ↑ "JSON Web Service". Yesodweb.com. Retrieved 2012-10-23.
* ↑ "The yesod-json package". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "book - Widgets". Yesodweb.com. Retrieved 2012-10-23.
* ↑ "The widget monad". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "The Writer monad". Haskell.org. Retrieved 2012-10-23.
* 1 2 3 "book - Shakesperean templates". Yesodweb.com. Retrieved 2012-10-23.
* ↑ "Class Text.Blaze.ToMarkup". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "Class Text.Cassius.ToCss". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "Class Text.Julius.ToJavascript". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "Class Text.Shakespeare.I18N.ToMessage". Hackage.haskell.org. Retrieved 2012-10-24.
* ↑ "Class Text.Shakespeare.Text.ToText". Hackage.haskell.org. Retrieved 2012-10-24.
* ↑ "Template Haskell". haskell.org. Retrieved 2012-11-03.
* ↑ "book - Internationalization". Yesodweb.com. Retrieved 2012-10-23.
* ↑ mkMessage
* 1 2 "HaskellWiki - QuasiQuotation". Haskell.org. 2012-05-26. Retrieved 2012-10-23.
* ↑ "Template Haskell Quasi-quotation". Haskell.org. Retrieved 2012-11-02.
* ↑ "The hamlet template module". Hackage.haskell.org. Retrieved 2012-10-23.
* 1 2 "The Julius template module". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "Roy language". Roy.brianmckenna.org. Retrieved 2012-10-23.
* ↑ "The Cassius template module". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "The Lucius template module". Hackage.haskell.org. Retrieved 2012-10-23.
* ↑ "Shakespeare plain text templates module". Hackage.haskell.org. Retrieved 2012-10-24.
* ↑ "The yesod-sitemap package". Hackage.haskell.org. Retrieved 2012-10-26.
* ↑ "The YesodBreadcrumbs class". Hackage.haskell.org. Retrieved 2012-11-05.
* ↑ "The yesod-newsfeed package for RSS / Atom views". Hackage.haskell.org. Retrieved 2012-10-26.