htl-spec icon indicating copy to clipboard operation
htl-spec copied to clipboard

Support map literals

Open kwin opened this issue 6 years ago • 6 comments

Currently it is not possible to create map literals (consisting of several key/value pairs) in HTL expression language. This would be especially handy for passing request attributes (see https://issues.apache.org/jira/browse/SLING-5812) which may now be given to data-sly-include. Currently one needs to have some backing code in JavaScript or Java to be able to use that option.

Maybe JSON notation would work

${'key1':'value1','key2':'value2'}

kwin avatar Jun 19 '18 06:06 kwin

Any progress or additional thoughts on this, @kwin ?

I'd love to see this make the Sightly/HTL asap, as we often end up creating backend logic for something as simple as adding a query string parameter to a URL.

It would be nice if a JSON-like syntax is supported, even though that could be tricky since { and } already have a special meaning. Especially since we're already supporting a JavaScript array syntax ([1, 2, 3]).

Are there any technical complications in using the JSON notation that you suggested? Or has this just not been a priority yet?

henrykuijpers avatar Jan 15 '20 14:01 henrykuijpers

This would rather be a question for @raducotescu. Any plans on a new HTL spec version where this could be included?

kwin avatar Jan 15 '20 14:01 kwin

I think it should be the normal javascript object initializer, allowing unquoted keys, and references to other variables. eg:

${{key1:'value1', 'key2':'value2'}}

// or
<li data-sly-list="${articles}" data="${{key1:'value1', key2:42, key3:item}}" ></li>

as a workaround, you can define the object in your use class.

tripodsan avatar Jan 16 '20 01:01 tripodsan

@raducotescu any update?

henrykuijpers avatar Jan 27 '20 10:01 henrykuijpers

@henrykuijpers, it's something we're discussing internally. As soon as we reach a conclusion we will post it here.

raducotescu avatar Jan 27 '20 10:01 raducotescu

Any way to vote on this proposal? I am also in favor, and agree JSON syntax seems like the way to go.

paulochang avatar Mar 19 '24 12:03 paulochang