Search code examples
node.jsnunjucks

nunjucks for loop and kebob-case


Using nunjucks on Node

Have a for loop that iterates over an array without any problems if I use snake_case

{% for item in items.micro_release %} <li>{{ item.id }}</li> {% else %} <li>No items found...</li> {% endfor %}

As soon as I try to use kebob-case (for internal naming convention clarity only). It fails.

{% for item in items.micro-release %} <li>{{ item.id }}</li> {% else %} <li>No items found...</li> {% endfor %}

I am assuming that it is treating "-" as an arithmetic operator. Tried

set micro_release = "micro-release"

to force it to behave like a string. That didn't work.

Given its python origin, is nunjucks kebob-intolerant :)? jk. thnx in advance for any words of wisdom on this one.


Solution

  • I am assuming that it is treating "-" as an arithmetic operator

    I think too.
    Try items['micro-release'].