I am trying to execute the following code snippet by using the conditional operator in sightly/htl:
but it is failing with the following error:
org.apache.sling.api.scripting.ScriptEvaluationException: ${author ? footer.root.path @ extension = 'html' : footer.root.path}: mismatched input '@' expecting {'.', 'in', '&&', '||', '[', ':'} in /apps/StateFarmAEM/components/product-footer-nav/product-footer-nav.html at line number 10 at column number 104
How to correct this expression
Please help
Solved! Go to Solution.
Views
Replies
Total Likes
As evident in the error description, Expression option(@) is not allowed within Ternary operator expression (instead as a whole upon conditional evaluation)
Example : Below is allowed in which case, extension is applied to both the scenarios. (will result in abc.html or xyz.html)
${request.parameterMap.firstName ? 'abc' : 'xyz' @ extension='html'}
For your use case, I would suggest to move the conditional logic to Sling Model and just use the footer.root.path
(Given that need for condition is itself whether or not to apply extension based on condition)
Hi @arjunsudhas1995 ,
Since ternary operator expects any of these symbols
{'.', 'in', '&&', '||', '[', ':'}
Try using the extension option in else part.
<a href="${!author ? footer.root.path : footer.root.path @ extension = 'html'}" class="-oneX-link--block text-gray-100">${footer.root.title}</a>
This would apply the extension in either case.
As evident in the error description, Expression option(@) is not allowed within Ternary operator expression (instead as a whole upon conditional evaluation)
Example : Below is allowed in which case, extension is applied to both the scenarios. (will result in abc.html or xyz.html)
${request.parameterMap.firstName ? 'abc' : 'xyz' @ extension='html'}
For your use case, I would suggest to move the conditional logic to Sling Model and just use the footer.root.path
(Given that need for condition is itself whether or not to apply extension based on condition)
according to my usecase I only want extension to be applied when condition is true
Handle the conditional logic in Sling Model.
Views
Likes
Replies
Views
Like
Replies