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

How to append a character while using the conditional statement in sightly?

Avatar

Avatar
Contributor
Level 2
jezwn
Level 2

Likes

9 likes

Total Posts

68 posts

Correct Reply

2 solutions
Top badges earned
Contributor
Shape 1
Springboard
Establish
Validate 1
View profile

Avatar
Contributor
Level 2
jezwn
Level 2

Likes

9 likes

Total Posts

68 posts

Correct Reply

2 solutions
Top badges earned
Contributor
Shape 1
Springboard
Establish
Validate 1
View profile
jezwn
Level 2

04-02-2020

I need to set the href value depending on the nullity of sling:vanityPath. The hit.properties.sling:vanityPath returns the string value for sling:vanityPath property. I need to append a '/' before the hit.properties.sling:vanityPath value. Is it possible to do that in the following code or do I have to test it twice, but that comes with code repetition?

<a href="${hit.properties.sling:vanityPath == null? hit.path : hit.properties.sling:vanityPath @ extension='html'}"/>

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Contributor
Level 2
jezwn
Level 2

Likes

9 likes

Total Posts

68 posts

Correct Reply

2 solutions
Top badges earned
Contributor
Shape 1
Springboard
Establish
Validate 1
View profile

Avatar
Contributor
Level 2
jezwn
Level 2

Likes

9 likes

Total Posts

68 posts

Correct Reply

2 solutions
Top badges earned
Contributor
Shape 1
Springboard
Establish
Validate 1
View profile
jezwn
Level 2

04-02-2020

The prependPath could be used to do this.

Answers (2)

Answers (2)

Avatar

Avatar
Contributor
Level 2
jezwn
Level 2

Likes

9 likes

Total Posts

68 posts

Correct Reply

2 solutions
Top badges earned
Contributor
Shape 1
Springboard
Establish
Validate 1
View profile

Avatar
Contributor
Level 2
jezwn
Level 2

Likes

9 likes

Total Posts

68 posts

Correct Reply

2 solutions
Top badges earned
Contributor
Shape 1
Springboard
Establish
Validate 1
View profile
jezwn
Level 2

27-02-2020

prependPath - prepends its content to the path that identifies a resource

 

${'path' @ prependPath='..'}
<!-- outputs: ../path -->

${'path' @ prependPath='/', appendPath='/'}
<!-- outputs: /path/ -->

${'http://example.com/path/page.html' @ prependPath='foo'}
<!-- outputs: http://example.com/foo/path/page.html -->

  Source: https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#125-uri-manipulation

Avatar

Avatar
Give Back 50
MVP
Vijayalakshmi_S
MVP

Likes

436 likes

Total Posts

574 posts

Correct Reply

191 solutions
Top badges earned
Give Back 50
Give Back 5
Ignite 10
Ignite 5
Ignite 3
View profile

Avatar
Give Back 50
MVP
Vijayalakshmi_S
MVP

Likes

436 likes

Total Posts

574 posts

Correct Reply

191 solutions
Top badges earned
Give Back 50
Give Back 5
Ignite 10
Ignite 5
Ignite 3
View profile
Vijayalakshmi_S
MVP

04-02-2020

HI, 

It is recommended to do any data manipulation in back end. Null check/equality check can be performed at sightly level. Amending a value based on some condition has to happen in back end and expose it in sightly via getter.