HTL Ternary operation with selectors and extensions

Avatar

Avatar

Ashwin_Raju

Avatar

Ashwin_Raju

Ashwin_Raju

28-10-2020

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? 

View Entire Topic

Avatar

Avatar

Suraj_Kamdi

MVP

Avatar

Suraj_Kamdi

MVP

Suraj_Kamdi
MVP

28-10-2020

@Ashwin_Raju 

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>