Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

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

Avatar

Level 6

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

1 Accepted Solution

Avatar

Correct answer by
Level 6

The prependPath could be used to do this.

View solution in original post

4 Replies

Avatar

Community Advisor

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.

Avatar

Correct answer by
Level 6

The prependPath could be used to do this.

Avatar

Level 6

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