Creating multiple attribute in sightly from string | Community
Skip to main content
December 20, 2016

Creating multiple attribute in sightly from string

  • December 20, 2016
  • 2 replies
  • 8077 views

Hello,

I am trying to create html attributes from a string with multiple attributes.

We have a string myAttrs = " class='myClass' id='myId' data-value='myCustomValue'".

I am trying to render that string as attributes of a html element.

Example input: <p ${myAttrs}> My paragraph </p>

Expected output: <p class='myClass' id='myId' data-value='myCustomValue'> My paragraph </p>

That does not work. Is there a sightly command to achieve my expected output without converting the string to a map and using data-sly-attribute?

Thank you

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Feike_Visser1
Adobe Employee
Adobe Employee
December 20, 2016

Have a look at data-sly-attribute, you can pass in a map.

https://docs.adobe.com/docs/en/htl/docs/block-statements.html

December 20, 2016

I know I can pass a map, but this a integration with a legacy system build using jsp and I would prefer not convert to a map. 

 

Tried 'context' and it didn't work.

December 20, 2016

Tried indeed several things, but it isn't working..

What about creating a use-class that converts the String to a Map?

Then your integration can stay as is.


Yeah, that probably is going to be the solution.

I just think it is odd sightly removed a basic jsp functionality.

sachind88574992
May 31, 2018

Has any one found a solution to this ?

Feike_Visser1
Adobe Employee
Adobe Employee
May 31, 2018

Use-api to convert String into Hashmap

sachind88574992
May 31, 2018

Thanks Feike....I made it work like this.

<sly data-sly-test.a=${item.parsysIds}></sly>

  <sly data-sly-test.b= "<dd ">

    ${a @context = 'unsafe'}${b @content='html'} class = "${item.parsysIds} ${wcmmode.edit ? '' : 'hide'}" id="${item.parsysIds}">

It returns me:

<dd notauthenticateduser class="notAuthenticatedUser hide" id="notAuthenticatedUser">