Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Getting the hostname using Sightly

Avatar

Level 1

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?

1 Accepted Solution

Avatar

Correct answer by
Employee

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

View solution in original post

4 Replies

Avatar

Correct answer by
Employee

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

Avatar

Employee Advisor

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

Avatar

Level 1

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.

Avatar

Level 4

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

${request.serverName}