Skip to main content
Level 4
Apr 4, 2016 9:40 AM UTC
Solved

Encoding url in sightly

Hi All,

Some of documents url have space in them, I want to encode them in sightly it is possible to do so.

I have tried using context uri but that also did not worked

${properties.jcr:title @ context='uri'} 
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
edubey
edubeyAccepted solution
Level 10
Apr 4, 2016 10:30 AM UTC

You can use JavaScript Use API,, assume this code is present in file name first.js

"use strict"; use(function () { eurl = encodeURI(this.url); return eurl; });

and call this via 

<sly data-sly-use.info="${'first.js' @ url=properties.jcr:title}"> <h1> ${info} </h1> </sly>

4 replies

edubey
Level 10
Apr 4, 2016 9:56 AM UTC

Are you documents present in AEM? If yes, I guess you wont have space in url as they will get replced by hypen '-'

You are you showing just document name  or make hyper links on them? let me know...

Translate
Level 4
Apr 4, 2016 10:08 AM UTC

These documents are not present inside AEM

Translate
edubey
edubeyAccepted solution
Level 10
Apr 4, 2016 10:30 AM UTC

You can use JavaScript Use API,, assume this code is present in file name first.js

"use strict"; use(function () { eurl = encodeURI(this.url); return eurl; });

and call this via 

<sly data-sly-use.info="${'first.js' @ url=properties.jcr:title}"> <h1> ${info} </h1> </sly>
Translate
Level 4
Apr 4, 2016 12:34 PM UTC

Thank you, Yes I can do something like this.

Translate