how to dynamically change data-attribute? for example data-off-right="${model.value1}", here i want "right" should be dynamic. how can i achieve this? | Community
Skip to main content
Level 4
June 11, 2021
Solved

how to dynamically change data-attribute? for example data-off-right="${model.value1}", here i want "right" should be dynamic. how can i achieve this?

  • June 11, 2021
  • 2 replies
  • 976 views
No text available
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kchaurasiya

Hi Karthick1356,

 

Have you tried in this way 

<sly data-sly-test.right=${right.value} />

 data-off-${right}="${model.value1}"

2 replies

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
June 11, 2021

Hi @karthick1356 ,

 

You can use 'data-sly-attribute' HTL block to achieve this. its supports map (key-value), and the key automatically becomes atribute in html mark-up.

Reference -

https://experienceleague.adobe.com/docs/experience-manager-htl/using/htl/block-statements.html?lang=en

https://www.youtube.com/watch?v=LhvSNVagoZk

kchaurasiya
kchaurasiyaAccepted solution
Level 5
June 11, 2021

Hi Karthick1356,

 

Have you tried in this way 

<sly data-sly-test.right=${right.value} />

 data-off-${right}="${model.value1}"