Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Closing div element inside sly element.

pranalim1653274
Level 2
Level 2

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
1 Accepted Solution
Nupur_Jain
Correct answer by
Community Advisor
Community Advisor

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.

 

 

 

View solution in original post

4 Replies
Arun_Patidar
Community Advisor
Community Advisor

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

pranalim1653274
Level 2
Level 2
yes so ColumnSubContainerClass will be multiple classes list of strings and we need to close the similar div's at the end.
Nupur_Jain
Correct answer by
Community Advisor
Community Advisor

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.

 

 

 

View solution in original post