Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Rendering a link that might be internal or external

Avatar

Level 4

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)

1 Accepted Solution

Avatar

Correct answer by
Level 3
5 Replies

Avatar

Level 10

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>

Avatar

Level 4

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

Avatar

Level 4

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.

Avatar

Level 3

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?

Avatar

Correct answer by
Level 3