From de4ec3e97039f34372e6cab76d1afee4860a966f Mon Sep 17 00:00:00 2001 From: Ryan Wilson Date: Tue, 22 Sep 2015 17:21:19 -0700 Subject: [PATCH] Added section to template documentation explaining mustache delimiters. --- doc/TEMPLATES.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/doc/TEMPLATES.md b/doc/TEMPLATES.md index a5503707..e2ffe390 100644 --- a/doc/TEMPLATES.md +++ b/doc/TEMPLATES.md @@ -93,6 +93,30 @@ generated project will contain a file named `README.md` where the header is [Mustache]: http://mustache.github.io/ [mustache-manual]: http://mustache.github.io/mustache.5.html +#### A warning about Mustache tag delimiters +Clojure syntax can conflict with the default mustache tag delimiter. For +example, when destructuring a nested map: + +```clj +(let [{{:keys [a b]} :ab} some-map] + (do-something a b)) +``` + +Stencil will interpret the `{{` as the start of a mustache tag, but since the +contents are not valid mustache, the render fails. To get around this, we can +change the mustache delimiter temporarily, like so: + +```clj +{{! Change mustache delimiter to <% and %> }} +{{=<% %>=}} + +(let [{{:keys [a b]} :ab} some-map] + (do-something a b)) + +<%! Reset mustache delimiter %> +<%={{ }}=%> +``` + ## Distributing your Template Templates are just maven artifacts. Particularly, they need only be on