mmontone / djula

Common Lisp port of the Django templating language
http://mmontone.github.io/djula/djula
MIT License
152 stars 21 forks source link

'loop' variable in 'for' tag #11

Closed fukamachi closed 9 years ago

fukamachi commented 9 years ago

Although Jinja2 has a special variable called loop (http://jinja.pocoo.org/docs/dev/templates/#for), Djula doesn't seem to have it.

For example, this is an HTML template which shows categories with a comma between each element.

  <dl>
    <dt>Categories</dt>
    <dd>
      {% for category in categories %}
      <a href="/search?q={{ category }}">{{ category }}</a>{% if not loop.last %}, {% endif %}
      {% endfor %}
    </dd>
  </dl>

As loop.last is always false, a comma is shown in the last of the line.

It'd be great if this feature is also available in Djula. Or, any other ideas to do it?

mmontone commented 9 years ago

This is supposed to be supported already, but it is undocumented and not sure if is working. I'm trying to add some tests and ensure something like your example works. After that, if I'm successful, I'll add the documentation.

mmontone commented 9 years ago

I've implemented loop variables access. You need to use forloop.last, forloop.first, etc.

I haven't documented it yet.

mmontone commented 9 years ago

I've also implemented arrays and hash-table iteration and updated the docs: http://mmontone.github.io/djula/doc/build/html/tags.html#std:templatetag-for