Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!

Managing internal and external links in Content Fragments and Graphql

Avatar

Level 1

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)?

 

 

3 Replies

Avatar

Level 3

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

 

Avatar

Level 1

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

Avatar

Level 3

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.

ClintLundmark_0-1708732736812.png

 

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.