Sightly - Link resolution (pathfield from dialog) | Community
Skip to main content
Level 3
October 16, 2015
Solved

Sightly - Link resolution (pathfield from dialog)

  • October 16, 2015
  • 10 replies
  • 4811 views

Hi,

How do I get the link resolved when using Sightly?

I have a 'pathfiled' in the dialog which points to one of the page in the site and I get this to the page in the href as below

<a href='${properties.imageorvideo == "image" ? (properties.url || "#") : "#"}' >

How do I add ".html" to this in Sightly?

Now the link on the site appears as '/content/mysite/abc'. No .html is added to the link (WITHOUT USING JAVA USE API)

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Runal_Trivedi

Hi,

You can use format method of sightly to form a formatted path url with extension

${ '{0} {1}' @ format=[url,extension]}

url and extension are again sightly variables, where url contains the page path - '/content/mysite/abc' and extension contains the value of extension you need i.e. '.html'

Do formatting only when url contains the non-blank value.

Thanks,

Runal

10 replies

Runal_Trivedi
Runal_TrivediAccepted solution
Level 6
October 16, 2015

Hi,

You can use format method of sightly to form a formatted path url with extension

${ '{0} {1}' @ format=[url,extension]}

url and extension are again sightly variables, where url contains the page path - '/content/mysite/abc' and extension contains the value of extension you need i.e. '.html'

Do formatting only when url contains the non-blank value.

Thanks,

Runal

b7wilso
Level 3
October 16, 2015

Hey @ashtrick, was wondering if you had had any further luck with this?  I am having a similar issue.  Even though it says on the documentation that links should be using the URI context by default for href's, I did try this to see if it made any difference, unfortunately it did not. 

<ul data-sly-list.child="${lfp.linkList}"> <li><a href="${child.linkLocation @ context='uri'}">${child.linkLabel}</a></li> </ul>

 

Thanks.

Lokesh_Shivalingaiah
Level 10
October 16, 2015

You can try with this

  1. <a href='${properties.imageorvideo == "image" ? (properties.url || "#") : "#"}'+'.html' >
ashtrickAuthor
Level 3
October 16, 2015

Runal.Trivedi wrote...

Hi,

You can use format method of sightly to form a formatted path url with extension

${ '{0} {1}' @ format=[url,extension]}

url and extension are again sightly variables, where url contains the page path - '/content/mysite/abc' and extension contains the value of extension you need i.e. '.html'

Do formatting only when url contains the non-blank value.

Thanks,

Runal

 

Not sure if I understand this correctly.. how do I assign values to url and extension? And, if the URL is an external URL there is no need to add HTML. So, how do I check if this is an external URL and assign values to sightly variables? Bit of code snippets are much appreciated.

Thanks,

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

Or you can do something like this:

  1. <a data-sly-test.imageOrVideo='${(properties.imageorvideo == "image" && properties.url)}' href='${properties.url}.html' >...</a>
  2. <a data-sly-test="${!imageOrVideo}" href="#">...</a>
ashtrickAuthor
Level 3
October 16, 2015

@b7wilso, Not in Sightly template directly.

I ended up in using Java Use API to handle the links - check if it is an internal URL, then add ".html" to it

Runal_Trivedi
Level 6
October 16, 2015

I guess with what you suggested it is going to append '.html' with '#' as well.

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

What is not working in this case?

The @ context is doing the escaping, but won't add the .html to your url.

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

And the + is not supported in sightly...

ashtrickAuthor
Level 3
October 16, 2015

Feike Visser wrote...

Or you can do something like this:

  1. <a data-sly-test.imageOrVideo='${(properties.imageorvideo == "image" && properties.url)}' href='${properties.url}.html' >...</a>
  2. <a data-sly-test="${!imageOrVideo}" href="#">...</a>

 

Thanks for the response. How do I check if the properties.url is an internal url or not and add .html ?

Thanks,