How to append a character while using the conditional statement in sightly? | Community
Skip to main content
jezwn
Level 5
Feb 4, 2020 2:04 PM UTC
Solved

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

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'}"/>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
jezwn
jezwnAccepted solution
Level 5
Feb 5, 2020 7:13 AM UTC

The prependPath could be used to do this.

4 replies

jezwn
jezwnAuthor
Level 5
Feb 28, 2020 7:43 AM UTC

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

Translate
jezwn
jezwnAuthorAccepted solution
Level 5
Feb 5, 2020 7:13 AM UTC

The prependPath could be used to do this.

Translate
Vijayalakshmi_S
Level 10
Feb 4, 2020 4:40 PM UTC

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.

Translate
jezwn
jezwnAuthor
Level 5
Feb 5, 2020 7:14 AM UTC
You could use prependPath instead in sightly.
Translate