Sly logic mismatching | Community
Skip to main content
JakeCham
Level 6
April 19, 2022
Solved

Sly logic mismatching

  • April 19, 2022
  • 2 replies
  • 1261 views

Hi Team,

 

I have a simple sly logic to wrap a div in two places and it is not working for closing div. any suggestions ?

<sly data-sly-test="${false}">  // this sly isn't going inside when it is false as expected
    <div> //opening div
</sly>
//HERE OTHER HTL AND HTML CODE IS THERE


<sly data-sly-test="${false}"> // this sly is going inside even it is false
   test1   //this line is not executing when condition of sly is false as expected

      </div>  //closing div, this line is executing when condition of sly is false

   test2   //this line is executing  when condition of sly is false
</sly>

output when false

 

</div>

test2

 

So at the end I'm experiencing an extra closing div. The opening div hasn't been executing while ending div executing with the same logic that make a extra closing div in the html structure. Any suggestion would be appreciated.

Thank in advance 

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 arunpatidar

use data-sly-unwarp

 

<div data-sly-unwrap="${false}"> // here otehr htl code </div> outputs: <div> // here otehr htl code </div>

 

2 replies

Shubham_borole
Community Advisor
Community Advisor
April 19, 2022

@jakecham 

Have you tried 

<div  data-sly-test.var="a" > Show content here</div>


If the condition is met, the content and div would be shown, if not nothing will show is what I understand.

JakeCham
JakeChamAuthor
Level 6
April 19, 2022

<sly data-sly-test="${false}"> /
    <div>        // when the result is false this line isn't executing as expected
</sly>
//HERE OTHER HTL CODE IS THERE
<sly data-sly-test="${false}"> // this sly is not working as expected while same logic at top is working

    a      // when the result is false this line isn't executing as expected
    </div> // when the result is false still this line is executing 

    b // when the result is false still this line is executing 
</sly>

 

here when it is false sly logic on top is working but sly logic at bottom is not working.when result is false bottom sly logic is going inside and executing and printing </div> and ''b''.

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
April 19, 2022

use data-sly-unwarp

 

<div data-sly-unwrap="${false}"> // here otehr htl code </div> outputs: <div> // here otehr htl code </div>

 

Arun Patidar
JakeCham
JakeChamAuthor
Level 6
April 19, 2022

<sly data-sly-test="${false}"> /
    <div>        // when the result is false this line isn't executing as expected
</sly>
//HERE OTHER HTL CODE IS THERE
<sly data-sly-test="${false}"> // this sly is not working as expected while same logic at top is working

    a      // when the result is false this line isn't executing as expected
    </div> // when the result is false still this line is executing 

    b // when the result is false still this line is executing 
</sly>

 

here when it is false sly logic on top is working but sly logic at bottom is not working. When the result is false bottom sly logic is going inside and executing and printing </div> and ''b''.

arunpatidar
Community Advisor
Community Advisor
April 20, 2022

Hi,

You need to use data-sly-unwrap not data-sly-test to remove or add parent divs based on some condition.

 

Arun Patidar