A toolkit for making compile-time interpolated templates

Version on this page:2.0.24
LTS Haskell 22.29:
Stackage Nightly 2024-07-18:
Latest on Hackage:

See all snapshots shakespeare appears in

MIT licensed and maintained by Michael Snoyman
This version can be pinned in stack with:shakespeare-2.0.24@sha256:6c298960bc2eaa7c58310ce6a5ec6c5405bb03018104a67ddc0c6974cc0c3c00,4721

Shakespeare is a family of type-safe, efficient template languages. Shakespeare templates are expanded at compile-time, ensuring that all interpolated variables are in scope. Variables are interpolated according to their type through a typeclass.

Shakespeare templates can be used inline with a quasi-quoter or in an external file.

Note there is no dependency on haskell-src-extras. Instead Shakespeare believes logic should stay out of templates and has its own minimal Haskell parser.

Packages that use this: xml-hamlet

Please see the documentation at for more details.


ChangeLog for shakespeare


  • Fix build errors with GHC 8.10.1-alpha2 #245


  • Add support to use caret interpolation in only var shakespeares #242


  • Add stextFile to Text.Shakespeare.Text, which can be used to produce Text directly in the same way shamletFile can be used to produce Html directly. #240


  • Support for GHC 8.8


  • Restore allowing GHC to detect changes to i18n message files in GHC >= 8.4.


  • Change of the default behaviour of *File functions, they now will add their templates’ source file to ghc-dependencies, thus recompiling on templates’ changes.


  • ToJavascript instance for String, Strict and Lazy Text #227


  • Fix parse pattern-match with operator constructor #222


  • Updated encodeToTextBuilder also escapes single quotes #221


  • Semigroup instances

  • Handle expressions with infix operator and trailing spaces #211


  • Fix Cassius and Lucius reload mode #206


  • Expose Text.Internal.Css #205

  • New contentHash parser breaks hash hrefs #200


  • Parser fails without space between class and ID (Hamlet) #197

  • Support for template-haskell 2.12.0 #196

  • Handle parsing of trailing semicolon after mixins #194


  • Export hamletFromString #191


  • Added ixhamlet #177


  • Better empty HTML tag list

  • Make it work with ghc-8.0 #181


  • Improve docs in Text.Hamlet #180


  • Include aeson’s JSON encoding and escape <, > and & to avoid XSS attacks


  • Provide the Text.Hamlet.Runtime module


  • Drop system-filepath

Fix build for GHC 7.10 #151



  • cassiusMixin added

GHC 7.10 support

shakesepare 2.0.2

shakespeare-i18n supports message directories.

Hamlet 0.5.0 (August 29, 2010)

  • Use can use parantheses when referencing variables. This allows you to have functions applied to multiple arguments.

  • Added the hamlet’ and xhamlet’ quasiquoters for generating plain Html values.

  • Added runtime Hamlet support.

  • Added “file debug” support. This is a mode that is a drop-in replacement for external files compiled via template haskell. However, this mode also has a runtime component, in that is reads your templates at runtime, thus avoiding the need to a recompile for each template change. This takes a runtime hit obviously, so it’s recommended that you switch back to the compile-time templates for production systems.

  • Added the Cassius and Julius template languages for CSS and Javascript, respectively. The former is white-space sensitive, whereas the latter is just a passthrough for raw Javascript code. The big feature in both of them is that they support variable interpolation just like Hamlet does.

New in Hamlet 0.4.0

  • Internal template parsing is now done via Parsec. This opened the doors for the other changes mentioned below, but also hopefully gives more meaningful error messages. There’s absolutely no runtime performance hit for this change, since all parsing is done at compile time, and if there is any compile-time hit, it’s too negligible to be noticed.

  • Attribute values can now be quoted. This allows you to embed spaces, periods and pounds in an attribute value. For example: [$hamlet|%input!type=submit!value=“Add new value”|].

  • Space-delimited references in addition to period-delimited ones. This only applies to references in content, not in statements. For example, you could write [$hamlet|$foo bar baz$|].

  • Dollar-sign interpolation is now polymorphic, based on the ToHtml typeclass. You can now do away with $string.var$ and simply type $var$. Currently, the ToHtml typeclass is not exposed, and it only provides instances for String and Html, though this is open for discussion.

  • Added hamletFile and xhamletFile which loads a Hamlet template from an external file. The file is parsed at compile time, just like a quasi-quoted template, and must be UTF-8 encoded. Additionally, be warned that the compiler won’t automatically know to recompile a module if the template file gets changed.