[Thread Edited By Adobe]
/*Don’t forget to meet and greet your fellow peers virtually by telling them about yourself here.
Go ahead and to it now: https://adobe.ly/3eDnB4v */
Actual Post:
Hi All,
In my sightly code I have two page properties which I am successfully getting from my Java WCMUse class.
${bean.getProperty1} and ${bean.getProperty2}.
I am able to print these values.
#1] However, inside <p></p> tag, I need to have a logic such that it should check if ${bean.getProperty1} is available. If yes, print that , else print the second property.
I am trying the below :
#2] <p class="article-label">"${bean.getProperty1}?${bean.getProperty1}:${bean.getProperty2}"</p>
But its not coming up properly on the page. By that I mean say value1 and value2 are corresponding properties and if property1 is present its printing "value1?value1:" on the page, rather than just a single value.
Any thoughts/pointers on this will be very helpful.
Solved! Go to Solution.
Hi All,
Thanks a lot for your reply.
Tried the below :
"${property1 || property2}" and it worked.
Views
Replies
Total Likes
Use data-sly-test to check for existence, which u can also store in a variable as result.
Read docs for this: https://github.com/Adobe-Marketing-Cloud/sightly-spec/blob/master/SPECIFICATION.md#225-test
Views
Replies
Total Likes
Hi Praveen,
Thank you for your reply.
Somehow, I am not quite getting as to why its giving output as "value1?value1:" .
If you can provide a snippet, it would be helpful.
Views
Replies
Total Likes
You're printing out the string literals for all the values, without processing them. The three expressions in the ternary operator are being evaluated in isolation from one another. You should move the statements within a singel expression tag (${}).
<p class="article-label">${'{0}' @format=[bean.getProperty1?bean.getProperty1:bean.getProperty2]}</p>
askdctm wrote...
Hi Praveen,
Thank you for your reply.
Somehow, I am not quite getting as to why its giving output as "value1?value1:" .
If you can provide a snippet, it would be helpful.
Hi
Please have a look at this post:-
Link:- http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-1/
//
<ul data-sly-list.child="${currentPage.listChildren}">
<li class="${ childList.odd ? 'odd' : 'even'}">${child.title}</li>
</ul>
Link:- http://stackoverflow.com/questions/24550498/conditional-attributes-in-sightly-templates-aem-cq
//
Ternary conditional operator
<ul data-sly-list="${items}" class="${condition1 ? 'selected' : ''}">
<li class="${condition2 ? 'selected' : ''}">
Lots of other markup here
</li>
</ul>
I hope this will help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
Hi All,
Thanks a lot for your reply.
Tried the below :
"${property1 || property2}" and it worked.
Views
Replies
Total Likes
Could you please elaborate on your solution? Bit Urgent
Views
Replies
Total Likes