mmontone / djula

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

using length filter as boolean for if conditionals #82

Closed challmand closed 2 years ago

challmand commented 2 years ago

Hello I am trying to use the length filter to see if my list is a specific size.

{% if list | length >= 2 %} does not work {% if list | length_is:"2" %} does not work

creating my own filter to do the logic I want does not work.

Is there something I am missing? I get the following errors:

{% if boards | length > 4 %}

{% endif %}

An unhandled error condition has been signalled:
there was an error parsing the tag if boards | length_is:"4" 
{% if boards | length > 4 %}
{% endif %}

An unhandled error condition has been signalled:
there was an error parsing the tag if boards | length > 4 
{{ boards | length_is:"3" }}

An unhandled error condition has been signalled:
{# Error: There was an error rendering the token (VARIABLE (BOARDS) (LENGTH_IS 3)) : Translation backend has not been setup #}
{{ boards | length }}

3

How can I make a comparison boolean statement that works with if conditionals?

If I set the boards length to a variable i pass into the template the comparisons works fine, its only when I want to compare the length of a list inside the template I have the issues.

Appreciate any help.

vindarel commented 2 years ago

You can use boards.length:

  {% ifequal cards.length 3 %}
  yes :)
  {% else %}
  no :(
  {% endifequal %}

or {% if cards.length == 3 %}

this will call (length boards).

Maybe more examples can be added in the documentation?

challmand commented 2 years ago

You can use boards.length:

  {% ifequal cards.length 3 %}
  yes :)
  {% else %}
  no :(
  {% endifequal %}

or {% if cards.length == 3 %}

this will call (length boards).

Maybe more examples can be added in the documentation?

Thank you, just what I needed. I was taking the documentation too literally and did not see that variation.