Skip to main content
JakeCham
Level 6
May 4, 2023
Solved

Getting host name using HTL

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Shiv_Prakash_Patel
Shiv_Prakash_PatelAccepted solution
Community Advisor
May 4, 2023

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

3 replies

Shiv_Prakash_Patel
Community Advisor
Shiv_Prakash_PatelCommunity AdvisorAccepted solution
Community Advisor
May 4, 2023

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

 

Translate
Shiv Prakash
JakeCham
JakeChamAuthor
Level 6
May 4, 2023

Thanks a lot!! 

Translate
ShubhanshuSi2
Community Advisor
Community Advisor
May 4, 2023

@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.)

Translate
Shubhanshu Singh | Technical Architect | AEM Assets & Sites