Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

HTL Ternary operation with selectors and extensions

Avatar

Avatar
Validate 1
Level 3
Ashwin_Raju
Level 3

Likes

7 likes

Total Posts

44 posts

Correct Reply

4 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 3
View profile

Avatar
Validate 1
Level 3
Ashwin_Raju
Level 3

Likes

7 likes

Total Posts

44 posts

Correct Reply

4 solutions
Top badges earned
Validate 1
Boost 5
Boost 3
Boost 1
Affirm 3
View profile
Ashwin_Raju
Level 3

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? 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Springboard
MVP
Suraj_Kamdi
MVP

Likes

142 likes

Total Posts

155 posts

Correct Reply

41 solutions
Top badges earned
Springboard
Validate 1
Establish
Contributor
Ignite 3
View profile

Avatar
Springboard
MVP
Suraj_Kamdi
MVP

Likes

142 likes

Total Posts

155 posts

Correct Reply

41 solutions
Top badges earned
Springboard
Validate 1
Establish
Contributor
Ignite 3
View profile
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> 

Answers (2)

Answers (2)

Avatar

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

138 likes

Total Posts

188 posts

Correct Reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile

Avatar
Give Back 3
MVP
Manjunath_K
MVP

Likes

138 likes

Total Posts

188 posts

Correct Reply

61 solutions
Top badges earned
Give Back 3
Give Back
Boost 50
Boost 5
Boost 3
View profile
Manjunath_K
MVP

28-10-2020

Hi @Ashwin_Raju 

We can use ternary operation as mentioned below.

 

${slingModel.someLink @ selectors = slingModel.shouldHaveSelector ? 'content' : '', extension = 'html'}

 

 

Hope this helps!

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

271 likes

Total Posts

320 posts

Correct Reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

28-10-2020

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