I'm trying to write a HTL statement using ternary operation with selectors and extension. But html is not compiling and throwing error.
${slingModel.shouldHaveSelector ? slingModel.someLink @ selectors='content', extension = 'html' : slingModel.someLink @ extension = 'html' }
Checked in HTL docs, but there is no mention of using ternary operations with extension and selectors.
Any help on the right syntax to be used?
Solved! Go to Solution.
Views
Replies
Total Likes
correct way to write the expression is as follow
${slingModel.shouldHaveSelector ? slingModel.someLink : slingModel.someLink @ selectors='content', extension = 'html' }
but in your case please rewrite the logic as
<sly data-sly-test={slingModel.shouldHaveSelector}> {slingModel.somelink @ selectors='content', extension = 'html'}</sly>
<sly data-sly-test={!slingModel.shouldHaveSelector}> {slingModel.somelink @ extension = 'html'}</sly>
correct way to write the expression is as follow
${slingModel.shouldHaveSelector ? slingModel.someLink : slingModel.someLink @ selectors='content', extension = 'html' }
but in your case please rewrite the logic as
<sly data-sly-test={slingModel.shouldHaveSelector}> {slingModel.somelink @ selectors='content', extension = 'html'}</sly>
<sly data-sly-test={!slingModel.shouldHaveSelector}> {slingModel.somelink @ extension = 'html'}</sly>
Views
Replies
Total Likes
Hi @Ashwin_Raju
Use the below modified expression with one line. Your expression is wrong. Inside expression, upon a condition you can append or add String but can't send parameters(use @).
${slingModel.someLink @ extension = 'html', selectors= slingModel.shouldHaveSelector ? 'content' : ' ' }
Note: Added space in between single quotes of else to differentiate with double quote.
AG
Hi @Ashwin_Raju
We can use ternary operation as mentioned below.
${slingModel.someLink @ selectors = slingModel.shouldHaveSelector ? 'content' : '', extension = 'html'}
Hope this helps!
Views
Likes
Replies