Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Rendering a link that might be internal or external

Joel_Triemstra1
Level 4
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
iainc65537558
Correct answer by
Level 3
Level 3
0 Replies
edubey
Level 10
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>

Joel_Triemstra1
Level 4
Level 4

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

Joel_Triemstra1
Level 4
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.

iainc65537558
Level 3
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?

iainc65537558
Correct answer by
Level 3
Level 3