3 ms·
Hmm, I've only used enlive on a small project, and that was quite a while back (I haven't done any webdev lately) and I generally ended up marking my templated
by pmjordan 14y ago
Hmm, I've only used enlive on a small project, and that was quite a while back (I haven't done any webdev lately) and I generally ended up marking my templated elements with special ids or classes. Artificial example coming up:
<ul>
<li class="item-template">
<a href="#" class="item-link-template"><strong class="item-caption-template">Some dummy caption</strong></a>
— <span class="item-description-standin">Some dummy description</span>
</li>
</ul>
The item-template marks the outer-most element to use for repetition. The item-link-template can be used to set the href attribute. The contents of the tag marked with item-caption-template will be replaced with whatever content. The item-description-standin gets replaced with content outright. If you, say, want to remove the <strong> tags around the caption, just move the templating class to the parent item.
<ul>
<li class="item-template">
<a href="#" class="item-link-template item-caption-template">Some dummy caption</a>
— <span class="item-description-standin">Some dummy description</span>
</li>
</ul>
If you come up with some conventions, e.g. "-standin" gets replaced completely, whereas "-template" just gets transformed; each marker is only used for one purpose (don't conflate the link and the caption marker in the latter example), it works rather well, probably better than any other templating system I've used.
My only gripes with Enlive at the time were that it was overly macro-heavy (def'ing everything as opposed to returning values), and loading templates was quite slow, which made on-the-fly modifications to HTML generated elsewhere ineffecient. I suspect both are better these days, as it was still heavily in development at the time.