tera icon indicating copy to clipboard operation
tera copied to clipboard

Support for maps in the template language

Open yacoob opened this issue 6 years ago • 3 comments
trafficstars

As far as I can tell, you can create arrays in a template, but not a map. It'd be useful to have map support, so you can create maps and use map literals. There's already support for working with maps provided in the context (eg. get).

Is this a feasible request or is there something inherently problematic with it?

Thanks for considering!

yacoob avatar Jun 24 '19 02:06 yacoob

It is feasible, just not on my roadmap as it is pretty niche imo

Keats avatar Jun 24 '19 08:06 Keats

I could implement this using filters. Since you can already create arrays, you could use a filter to extend it like this:

{% set x = [] | setmap(attribute="a", value="b") %}

It would work like a setter counterpart for map. Does that sound good @Keats?

haselkern avatar Jul 27 '20 19:07 haselkern

Ideally I would prefer having map creation be a built-in feature but that requires quite a lot of changes to the parser and I'm not too confident in pest right now to add more to it.

Keats avatar Jul 28 '20 11:07 Keats