Rendering a link that might be internal or external | Community
Skip to main content
Level 3
Dec 11, 2017 12:53 PM UTC
Solved

Rendering a link that might be internal or external

I'd like to allow authors to specify the href of a link by either using the pathbrowser to browse to a path on the site like /content/site/path/to/page, or pasting in an external URL, like http://www.example.com. In the first case, I would want to append .html; in the second, I wouldn't. This seems like a reasonably common scenario, so I was thinking there might be some OOTB support, either in Java APIs, or Sightly/dialog functionality. I haven't found anything yet - is there anything? Or ACS Commons? (I'm using AEM 6.1 and Touch UI)

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
iainc65537558Accepted solution
Level 3
Mar 21, 2018 12:35 PM UTC

5 replies

iainc65537558Accepted solution
Level 3
Mar 21, 2018 12:35 PM UTC
Level 3
Mar 20, 2018 4:55 PM UTC

I am having the same issues here - entry pages seem to work fine, but anything deeper gets the .html added to the URL.

<a href="${ '/content/myproject/en' @ extension='html'}">Internal Link</a>   Adds the .html extension [correct]

<a href="${ 'https://www.adobe.com' @ extension='html'}">External Link</a> Does not add the .html extension [correct]

<a href="${ 'https://www.adobe.com/uk' @ extension='html'}">Deeper External Link</a> Adds the .html extension [not right]

This does seem like a bug - unless we are doing it wrong.  In which case is there a better way to output a link correctly that could be either external or internal?

Translate
Level 3
Dec 11, 2017 3:36 PM UTC

I just ran a few more tests, and looks like this is functionality that updated in 6.3. 6.1 and 6.2 append .html to everything, 6.3 distinguishes between internal and external links.

Translate
Level 3
Dec 11, 2017 2:52 PM UTC

Have you tried that against v6.1? My test was showing the latter example DID add .html to the external URL.

Translate
edubey
Level 10
Dec 11, 2017 1:48 PM UTC

You can use @ extension attribute in sightly

Example:

Will add .html to the internal page url

<a href="${ '/content/project/en' @ extension='html'}">Internal Link </a>

Will not add .html to the external domain url

<a  href="${ 'http://www.adobe.com' @ extension='html'}">External Link </a>

Translate