Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Getting host name using HTL

Avatar

Level 7

Hi Team,

 

I want to get the host name according to environments such as author , publisher and despatcher.

So I tried using java script like below.

window.location.hostname;

but my code is inside base page component. So it is saying window is not defined. Is there any way we can get the host name using HTL ?

 

Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @JakeCham 

You can get server details in sightly from request object as below.

<div>The Scheme (http/https) is ${request.scheme}</div>
<div>The hostname(domain) is ${request.serverName}</div>
<div>The port is ${request.serverPort}</div>
<div>The request URI is ${request.requestURI}</div>

Regards

Shiv

 

Shiv Prakash

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hi @JakeCham 

You can get server details in sightly from request object as below.

<div>The Scheme (http/https) is ${request.scheme}</div>
<div>The hostname(domain) is ${request.serverName}</div>
<div>The port is ${request.serverPort}</div>
<div>The request URI is ${request.requestURI}</div>

Regards

Shiv

 

Shiv Prakash

Avatar

Community Advisor

@JakeCham , although @Shiv_Prakash_Patel 's response is perfectly fine for your query.

If you are trying to create an absolute URL or externalLink. Try using Exernalizer service in your Sling Model (which can be tied to a runmode config) and then get it in sightly. 
Externalizing URLs | Adobe Experience Manager
Externalizer (The Adobe AEM Quickstart and Web Application.)