Expand my Community achievements bar.

SOLVED

Sightly - Link resolution (pathfield from dialog)

Avatar

Level 3

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

10 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Level 3

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.

Avatar

Level 10

You can try with this

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

Avatar

Level 3

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,

Avatar

Employee

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>

Avatar

Level 3

@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

Avatar

Community Advisor

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

Avatar

Employee

What is not working in this case?

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

Avatar

Employee

And the + is not supported in sightly...

Avatar

Level 3

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,