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  ,
 * route expressions with : safe (typed) urls as  ,
 * message expressions with : i18n message rendering as
 * other Haskell expressions with : haskell expression rendering as   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 &lt;iso-language&gt;.msg with entries like

ArticleUnexistant param@Int64: unexistant article #{param}

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  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   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
[lt| Mr./Mrs. #{fullName} ...
 * for e-mail or text/plain http content type.
 * 1) templates: lt: lazy text, st: strict text
 * 2) 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.