Using Filter in Clojure Selmer
Contents
I am using Clojure & Compojure to write my webpages, and I am trying to use Selmer as template system for Clojure.
Today I find a strange thing in my template file. I used following code to take the position of real content:
{{content}}
Then I generate real html content in my clojure code like this:
(defn index-render [params] “render file content of index.html” (let [basecon “to be done”] (render-file “./myproject/templates/front.tpl” {:content basecon})))
But after render the content, the page just shows following content:
to be done
and I printed the html result I found following content in html:
<B>to be done</B>
which means the render has escaped < and > to < and > for me.
The solution is very easy. Just use filter in template files.
Selmer is basically the same as The Django template language, so the Automatic HTML escaping is also basically the same. According to Filters part in Selmer online doc, the problem can be done by specifying a filter ‘safe’ following the name of the variable. The filters are separated using the | character.
So I change my templete file into
{{content|safe}}
and it works fine!
Author Watterry
LastMod 2014-01-22