Closing div element inside sly element.

Avatar

Avatar

pranalim1653274

Avatar

pranalim1653274

pranalim1653274

16-07-2020

Hi, 

I have requirement of below script.

<div class="${object.ColumnContainerClass}">
<sly data-sly-list="${object.ColumnSubContainerClass}" >
   <div class="${item @CONTEXT='text'}">
</sly>

Random code ...........

 

<sly data-sly-list="${object.ColumnSubContainerClass}">
   </div>
</sly>

</div>

 

but I am unable to get the </div> class inside sly.  even if ColumnSubContainerClass is empty div renders on the page. Please help.

 

Thanks in Advance

 

 

 

Adobe Experience Manager AEM 6.5

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Nupur_Jain

MVP

Avatar

Nupur_Jain

MVP

Nupur_Jain
MVP

16-07-2020

Hi @pranalim1653274 

 

Looks like you want outer div only if the object.ColumnSubContainerClass is not empty. you can achieve it using using data-sly-unwrap but you have to use it only if you want to print inner "Random code" even if the ColumnSubContainerClass is empty.

 

 

The Empty div is printing when object.ColumnSubContainerClass is empty because data-sly-list iterates once even if the value is empty. If you want to avoid it. check its value first using data-sly-test like

 

 

<div class="${object.ColumnContainerClass}">
<sly data-sly-test="${object.ColumnSubContainerClass}" data-sly-list="${object.ColumnSubContainerClass}" >
   <div class="${item @CONTEXT='text'}">

       Random code ...........

   </div>

</sly>

</div>

 

Try this out. Let me also know if your usecase is different.

 

Hope it helps!

Nupur.

 

 

 

Answers (1)

Answers (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831
Arun_Patidar
MVP

16-07-2020

Hi, 
What is your requirement, do you need to add all the classes to one div or need to generate multiple divs based on the list item.

Can you please share HTL and HTML example