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.
SOLVED

Sightly - Not able to assign value 'false' to a div property

Avatar

Level 3

I'm having this problem assigning value 'FALSE' to the <div> attribute.

I need to implement the following HTML

<div d-automode="${obj.message}"> <p>Content goes here</> </div>

Value for ${obj.message} will be  'true' or 'false'. All works fine when the value is TRUE. But, when the value is FALSE, sightly completely removes the attribute 'd-automode' and the resulting HTML is as below:

<div> <p>Content goes here</> </div>

Can someone please provide a solution on how to set value of 'false' fro this attribute?

Thanks,

1 Accepted Solution

Avatar

Correct answer by
Employee

This is indeed a current limitation, as the falsy values (including the literal 'false') are triggering the removal of the attribute.

One workaround is:

<div attr="false" data-sly-unwrap="${obj.message}"> <div attr="true" data-sly-unwrap="${!obj.message}"> <p>Contents here</p> </div> </div>

View solution in original post

5 Replies

Avatar

Employee

Can you try this?

<div data-sly-test.message="${'false'}"></div>

${message}

<div d-automode="${message ? 'true' : ' false '}">

    <p>Content goes here</>

</div>

Mind the spaces around false.

Avatar

Level 3

Sorry Feike,

FALSE value with space is not the solution. I'm using an API here which reads the value for this attribute and perform actions based on this. API expects the value true or false and not false with space.

Is there any other way of solving this issue? Or is it a bug?

Thanks,

-A

Avatar

Level 3

Thanks Feike for the response.

I have already tried this before as well.

<div data-sly-test.message="${'false'}"></div>        ---> No DIV elements rendered

${message}

<div d-automode="${message ? 'true' : ' false '}">

    <p>Content goes here</>

</div>

 

Output is

false

<div d-automode="&#x20;false&#x20;">

    <p>Content goes here</>

</div>

Avatar

Correct answer by
Employee

This is indeed a current limitation, as the falsy values (including the literal 'false') are triggering the removal of the attribute.

One workaround is:

<div attr="false" data-sly-unwrap="${obj.message}"> <div attr="true" data-sly-unwrap="${!obj.message}"> <p>Contents here</p> </div> </div>

Avatar

Level 3

Thanks Catalin for the workaround.

Do you have any workaround if there are multiple boolean attributes as below?

<div d-automode="${obj.message}" d-controls="${obj.controls}"> <p>Content goes here</> </div>

-A