Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Creating multiple attribute in sightly from string

Avatar

Level 3

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

14 Replies

Avatar

Employee

Sorry missed you final sentence :-)

Can you try @ context = 'unsafe'?

Avatar

Level 3

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.

Avatar

Employee

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.

Avatar

Level 3

Yeah, that probably is going to be the solution.

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

Avatar

Level 10

Once you get this solution working - enter it into the AEM Immerse contest - we are looking for all sort of workgin AEM Solutions: http://scottsdigitalcommunity.blogspot.ca/2016/12/win-passes-to-experience-manager.html

It may win you access to the AEM Virtual Conference in May where you will get access to lots of awesome AEM sessions. 

Avatar

Level 1

Has any one found a solution to this ?

Avatar

Level 1

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">

Avatar

Level 1

Only problem with this approach is that the query selector gets updated to all lower case as you might see in the above example(notauthenticateduser).

Do you know if this can be resolved?

Avatar

Level 10

Have you tried doing this use case with Sling Model and use Java logic to perform any data manipulation that you need - or are you trying all data manipulation in HTL syntax.

Avatar

Level 1

For the time-being i am trying only using HTL and the solution worked for me however only issue is that the selector gets updated to lower case..

Avatar

Level 10

One workaround is to use Sling Model and Java and use Java to modify the string to meet your requirements.

Avatar

Level 1

Tried that too. However when i do a ${local Identifier.Object Properties} it returns me a blank. If i do xyz = ${local Identifier.Object Properties}  then it renders me the proper authored value.