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
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
You can try with this
Views
Replies
Total Likes
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,
Views
Replies
Total Likes
Or you can do something like this:
Views
Replies
Total Likes
@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
Views
Replies
Total Likes
I guess with what you suggested it is going to append '.html' with '#' as well.
Views
Replies
Total Likes
What is not working in this case?
The @ context is doing the escaping, but won't add the .html to your url.
Views
Replies
Total Likes
And the + is not supported in sightly...
Views
Replies
Total Likes
Feike Visser wrote...
Or you can do something like this:
<a data-sly-test.imageOrVideo='${(properties.imageorvideo == "image" && properties.url)}' href='${properties.url}.html' >...</a>
<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,
Views
Replies
Total Likes