Managing internal and external links in Content Fragments and Graphql | Community
Skip to main content
March 16, 2023

Managing internal and external links in Content Fragments and Graphql

  • March 16, 2023
  • 2 replies
  • 1850 views

We are starting to use Content Fragments with GraphQL in AEM but found ourselves with a problem regarding links in CFs.

We have some Content Fragment models which have a Reference to pages, the client use this as a link or related content (using the PageRef's helper field _publishUrl).

The problem is that now we have some cases in which we need to point to a link that is not within AEM (external sites & deep links to mobile apps). These external links will return null if used in a Content Reference field in the CF. 

 

Example using this in a query:

 link {
... on PageRef{
_publishUrl
}
}

 

Will work fine if the field link points to an AEM page (which is to expect) but will return null if the author wrote https://example.com. One workaround would be to have 2 fields, but that seems cumbersome and a burden to the client.

 

What is the correct way to be able to manage links that could be either internal (pointing to pages within that AEM instance) or external (third party URLS)?

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

ClintLundmark
Level 3
August 4, 2023

Just out of curiosity was a solution ever provided or discovered?

 

Level 2
February 23, 2024

Hello @santiagozky , @clintlundmark : Have you guys found any solution to this?

ClintLundmark
Level 3
February 24, 2024

This is not a particularly good solution, but we had to move on, so it is what we did. It's more of a workaround or compromise.

 

In the Content Fragment Model, we have two properties that can be used for the link.

 

  • The actionLinkInternal property is a Content Reference data type configured to allow an author to select content within AEM. It has a description that indicates to select a page or an asset.
  • The actionLinkExternal property is a Single Line Text type configured using data validation, to only accept a valid URL.

 

In the GraphQL query we display PageRef and DocumentRef for the actionLinkInternal property and also output the actionLinkExternal property.

actionLinkInternal { ... on PageRef { _path _publishUrl } ... on DocumentRef { _path _publishUrl } } actionLinkExternal

The consuming application will have logic something like if there is a value in actionLinkExternal use that, otherwise use actionLinkInternal.