Getting the hostname using Sightly | Community
Skip to main content
junc70220741
October 16, 2015
Solved

Getting the hostname using Sightly

  • October 16, 2015
  • 4 replies
  • 7063 views

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.
Best answer by brucelef

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

brucelefAdobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

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

joerghoh
Adobe Employee
Adobe Employee
October 16, 2015

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

junc70220741
October 16, 2015

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.

crisr1
Level 4
July 7, 2016

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

${request.serverName}