Getting host name using HTL | Community
Skip to main content
JakeCham
New Participant
May 4, 2023
Solved

Getting host name using HTL

  • May 4, 2023
  • 2 replies
  • 1814 views

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

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

 

2 replies

New Participant
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.)

Shiv_Prakash_Patel
Shiv_Prakash_PatelAccepted solution
New Participant
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
JakeCham
JakeChamAuthor
New Participant
May 4, 2023

Thanks a lot!!