Stuart Sierra a écrit :
>  Very interesting, Christophe. I've been playing with StringTemplate
> <http://www.stringtemplate.org/> lately, but this separates design
> from code even further. Can it do conditionals, as in "if this
> variable is true, includes this HTML element"
In the only example, I use 'when-not to conditionally display an element.

(deftemplate microblog-template "net/cgrand/enlive_html/example.html" 
[title posts]
  [:title] title
  [:h1] title
  [:div.no-msg] (when-not (seq posts) ~(html/show))
  [:div.post] (for [{:keys [title body]} posts]
           ~(at
              [:h2] title
              [:p] body)))

see:

net.cgrand.enlive-html.examples=> (apply str (microblog-template "Hello user!"
             [{:title "post #1"
               :body "hello with dangerous chars: <>&"}
              {:title "post #2"
               :body "dolor ipsum"}]))
/"<html><head><title>Hello user!</title></head>
<body><h1>Hello user!</h1>
<div class=\"post\"><h2>post #1</h2>
<p>hello with dangerous chars: &lt;&gt;&amp;</p></div>
<div class=\"post\"><h2>post #2</h2>
<p>dolor ipsum</p></div></body></html>"

and:
/net.cgrand.enlive-html.examples=> (apply str (microblog-template "Hello 
Stuart!" []))

"<html><head><title>Hello Stuart!</title></head><body><h1>Hello Stuart!</h1>
<div class=\"no-msg\">Sorry, I'm too lazy to post.</div></body></html>"


But I'm not sure that's what you are asking for. Do you mean something 
else?
(Right now there's no facility to use another element than the currently 
selected one but it's planned if that's what you are interested in.)

Christophe

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to