tera icon indicating copy to clipboard operation
tera copied to clipboard

Can't (easily) index a literal array

Open ChrisJefferson opened this issue 1 year ago • 2 comments

I was trying to index a literal array, to get a label, for example:

['up', 'down', 'left', 'right'][1]

But this doesn't work, I get:

expected a filter or a variable end

Now, I can fix this by writing:

['up', 'down', 'left', 'right'] | nth(n=1)

But it took me a while to find that, and I expected the 'obvious thing' to work.

ChrisJefferson avatar Aug 19 '24 14:08 ChrisJefferson

I also found I can write {% x = ['up', 'down', 'left', 'right'] %}, then use {{ x[1] }}, so it's not too hard to work around, but the error message did confuse me for a while.

ChrisJefferson avatar Aug 20 '24 11:08 ChrisJefferson

I've added support for it in the next version: https://github.com/Keats/tera2/pull/42 Nice catch!

Keats avatar Aug 21 '24 12:08 Keats