Skip to main content
junc70220741
Oct 16, 2015 2:29 AM UTC
Solved

Getting the hostname using Sightly

Hello

Is it possible to get the hostname of the current page? 

currentPage.getPath() only returns something like '/path/path/page' but I also need to find the hostname, for example, 'https://www.google.com'

Is it possible? Or is there a good way of doing it?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
brucelefAccepted solution
Adobe Employee
Oct 16, 2015 2:29 AM UTC

Yes, it's possible. Check out the Externalizer service [0] for access to the hostname, and the Sightly Use-API [1] for exposing that value to your Sightly scripts.

[0] https://docs.adobe.com/docs/en/aem/6-1/develop/platform/externalizer.html

[1] http://docs.adobe.com/docs/en/aem/6-1/develop/sightly/use-api-in-java.html

4 replies

junc70220741
Oct 16, 2015 2:29 AM UTC

Thanks guys for the advice.

I'm now developing a sharing functionality, for example, click a button from a news page and it fires the Twitter api with the news page url.

Actually, I'm a bit surprised that it requires to modify the console.

Translate
joerghoh
Adobe Employee
Adobe Employee
Oct 16, 2015 2:29 AM UTC

Hi,

I don't think that it is a good idea to attach the hostname (and the protocol as well) to a link when you render a page. At least as long as you don't need to switch either server or protocol. If you stay all the time on https://mysite.com, you should just render relative links.

When you need to switch the hostname, you can use the Externalizer as suggested by Bruce. Or you might implement something custom.

kind regards,
Jörg

Translate
brucelefAdobe EmployeeAccepted solution
Adobe Employee
Oct 16, 2015 2:29 AM UTC

Yes, it's possible. Check out the Externalizer service [0] for access to the hostname, and the Sightly Use-API [1] for exposing that value to your Sightly scripts.

[0] https://docs.adobe.com/docs/en/aem/6-1/develop/platform/externalizer.html

[1] http://docs.adobe.com/docs/en/aem/6-1/develop/sightly/use-api-in-java.html

Translate
crisr1
Level 4
Jul 7, 2016 10:38 PM UTC

I think you could probably get it easier through the request global object..

${request.serverName}

Translate