Expand my Community achievements bar.

SOLVED

Configring Internal or External Link in Pathbrowser in AEM 6.2

Avatar

Level 2

I have a component of resource type - granite/ui/components/foundation/form/pathbrowser , i need to make sure in case of internal link .html to be appended whereas in case of external link it should be as it is no .html appending. Can anyone help?

1 Accepted Solution

Avatar

Correct answer by
Level 2

In case of Touch UI, we need to make use of Java Code only, I was not able to find any other options.

This is the code which I tried and it worked for me.

Here I am checking for the 4 cases:

1. Checking for file extension:- so if the file extension is .mp4 or .mp3 like that then we are not processing the URL and simply returning it.to check the different extension we have created an enum class. like this.

case 2: if URL is null or empty then we are sending null.

case 3: if URL starts with "/content" then we are appending ".html"

case 4: if URL starts with "http" or "https" or "www" then we are simply sending back the URL without performing any operation as it is an external link.

View solution in original post

6 Replies

Avatar

Level 9

Once you get user input and before displaying it as a link, check if this is internal page or not. You can PageManger & Resource API for this. 

ashish kumarm48760261 wrote...

I have a component of resource type - granite/ui/components/foundation/form/pathbrowser , i need to make sure in case of internal link .html to be appended whereas in case of external link it should be as it is no .html appending. Can anyone help?

 

Avatar

Level 4

Jitendra S.Tomar wrote...

Once you get user input and before displaying it as a link, check if this is internal page or not. You can PageManger & Resource API for this. 

ashish kumarm48760261 wrote...

I have a component of resource type - granite/ui/components/foundation/form/pathbrowser , i need to make sure in case of internal link .html to be appended whereas in case of external link it should be as it is no .html appending. Can anyone help?

 

 

 

The whole point is to avoid doing backend code checks. The "linkpattern" config options for pathfield would enable us to handle it all by itself.  Check the API here is the API snippet.

linkPattern : String

A pattern to format links after selection in the browse dialog (using CQ.Util.patchText). This is used when only a tree item is selected (which is always the case if parBrowse = false). It has only one argument '{0}', which is the path from the tree. See also parLinkPattern.
 

Defaults to '{0}.html' if parBrowse = true, otherwise simply '{0}'.

Writing an explict condition in the backend code to add .html is not required.

Avatar

Level 2

Yeah but here i am working in Touch UI (granite/ui/components/foundation/form/pathbrowser ) for AEM 6.2 , so this property seems to be invalid for this case.

Avatar

Level 6

Do we have an answer for this? How to configure this in touch UI pathbrowser?

Avatar

Level 1

Hi,

Did you get an answer to it how it could be accomplished in touchui?

Avatar

Correct answer by
Level 2

In case of Touch UI, we need to make use of Java Code only, I was not able to find any other options.

This is the code which I tried and it worked for me.

Here I am checking for the 4 cases:

1. Checking for file extension:- so if the file extension is .mp4 or .mp3 like that then we are not processing the URL and simply returning it.to check the different extension we have created an enum class. like this.

case 2: if URL is null or empty then we are sending null.

case 3: if URL starts with "/content" then we are appending ".html"

case 4: if URL starts with "http" or "https" or "www" then we are simply sending back the URL without performing any operation as it is an external link.