Array as a member of an array
Hello!
From https://tera.netlify.app/docs/#literals: "arrays: a comma-separated list of literals and/or idents surrounded by [ and ] (trailing comma allowed)"
Since array is a literal and array is a comma-separated list of literals I was wondering whether it's possible to have array as a member of another array.
This doesn't work:
{% set array = [12, True, 1.7, ["a", 'b', `c`]] %}
But this works:
{% set char_array = ["a", 'b', `c`] %}
{% set array = [12, True, 1.7, char_array] %}
This is inconsistent.
We should either:
- Allow array literal to be a member of array just like the way above via variable OR
- Update array description at https://tera.netlify.app/docs/#literals as: "arrays: a comma-separated list of literals (except array) and/or idents surrounded by [ and ] (trailing comma allowed)"
I think 1. makes more sense and maintains consistency.
The v2 parser already handles that correctly so i'll mark 1 as a v2 feature
Does v2 parser handle this too? continuing the above example:
{{ char_array in array }} // currently, this works
{{ ["a", 'b', `c`] in array }} // currently, this doesn't work
{{ not ('a' in char_array) }} // currently, this doesn't work
Thanks!
Also, from tera documentation for in operator:
While in the left hand side only literals/variables resulting in a number, a string and a boolean are supported.
But as demonstrated in above example, variables resulting in array are also supported in left hand side. Guess we need to update the docs...
Hi!
Since this is related to parser I'm not opening a fresh issue.
Does v2 parser handle this:
{% set char_array = ["a", 'b', `c`] %}
{{ char_array != char_array }} // Currently, this works
{{ ["a", 'b', `c`] == ["a", 'b', `c`] }} // This doesn't work
I'm not sure right now but it's a good testcase to add it, {{ char_array != char_array }} should be false and the next line should be true
First line is indeed false. But unfortunately, Tera throws parsing error on the next line. I hope v2 parser fixes that. :)
Adding more tests to check with parser v2.
Parentheses with filter:
{{ 1 + ("foo" | length) }} // currently, doesn't work
{{ (" foo " | trim) ~ "bar" }} // currently, doesn't work