See this google groups topic
Several people have expressed confusion with using clone-for
to insert a list of dynamically generated elements into a template which includes several dummy elements. For example, maybe the template looks like this,
<ul>
<li>foo</li>
<li>bar</li>
<li>baz</li>
</ul>
And we want to generate HTML like this,
<ul>
<li>real</li>
<li>data</li>
<li>here</li>
<li>wurdz</li>
</ul>
The naive thing to try is something like
(defsnippet my-snippet "my-template.html" [:ul] [items]
[[:li first-of-type]] (clone-for [ii items]
[:li] (content ii)))
But that leaves the 2nd through nth elements with the dummy data. How can we simply remove all the dummy elements and replace with real one?
The solution I've been using is to do something like,
(defsnippet my-snippet "my-template.html" [:ul] [items]
[[:li (html/but html/first-of-type)]] nil
[[:li html/first-of-type]] (html/clone-for [ii items] ...))
Which deletes all the dummy nodes, and inserts new ones with my content.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With