Mark,
Yes, you can do nested loops. Say you have a structure like this:
{:title "Hello"
:slides
[{:caption "World"
:images
[{:path "/img/world.png"}
{:path "/img/space.png"}]}
{:caption "Jupiter"
:images
[{:path "/img/callisto.png"}
{:path "/img/ganymede.png"}]}]}
You can render this using the following template:
{{title}}
{{#slides}}
{{caption}}
{{#images}}
<img src="{{path}}" />
{{/images}}
{{/slides}}
to produce this output:
Hello
World
<img src="/img/world.png" />
<img src="/img/space.png" />
Jupiter
<img src="/img/callisto.png" />
<img src="/img/ganymede.png" />
There are even loop vars to reference the item and outer items from inside
the loop:
{{loop.item}}
{{loop.outer.item}}
{{loop.outer.outer.item}}
You can also bind each item in the loop if you don't like the implicit
context:
{{title}}
{{#slides:slide}}
{{slide.caption}}
{{#slide.images:image}}
<img src="{{image.path}}" />
{{/images}}
{{/slides}}
For the full list of loop variables available from inside a loop check out
the template docs: http://caribou.github.io/caribou/docs/templates.html
On Sunday, November 17, 2013 11:47:12 PM UTC-8, puzzler wrote:
>
> The template example shows a notation for doing something special on the
> last iteration of a loop, but it doesn't look like this syntax can handle
> nested loops. Is there any mechanism for nested loops?
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.