Adobe Tech Blog

News, updates, and thoughts related to Adobe, developers, and technology.

Follow publication

MSM/Live Copy : Rewrite Reference Links Inside Experience Fragments or Template Structure Content

--

The problem

Have you ever experienced this problem? Whenever you create a live copy/roll-out a master page, all the reference links inside a page get updated to the live copy equivalent links automatically; however, this is applicable only for the links which are stored inside a component property or page property in a page. If there are links referenced in editable template structure content or inside an experience fragment, which is used in a master page, it won’t be updated to the live copy equivalent link on roll-out. This is because these are shared or global content, which will be stored in one location (“/conf” or “/content/experience-fragments”).

The solution

Here is the solution: Use a custom “Link Transformer” to rewrite master links into live copy equivalent links.

The steps to implement a custom Link Transformer

Create a Transformer Factory

Create the Transformer Class

  1. In the init method, get the current resource or page.
  2. Check if the current page is a live copy or part of the live copy site.
  3. If the current page is live copy, get the blueprint path (“/content/path/to/master-site”) and get the live copy path (“/content/path/to/livecopy-site”).
  4. In the “startElement” method of the transformer, get the anchor link and replace the “/content/path/to/master-site” with “/content/path/to/livecopy-site”.

Add the transformer config

  1. Add the config node to /apps/<project>/config/rewriter

2. Include the transformer type and don’t forget to include the linkchecker (default OOTB transformer).

3. Specify the resource type which will be the page component resource type.

4. Specify the content paths for which the transformer is applicable.

Key notes

  1. The solution is applicable for one level of live copy. This can be modified to get all the blueprint paths recursively, and the same can be used to replace the links.
  2. The solution is applicable only for anchor links. This can be modified to check for any other HTML tags or attributes, where a page link can be expected.

References

  1. Sling Rewriter — https://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter.html
  2. Live Relationship Manager API — https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/com/day/cq/wcm/msm/api/LiveRelationshipManager.html

Any suggestions or questions? Please feel free to comment.

--

--

Published in Adobe Tech Blog

News, updates, and thoughts related to Adobe, developers, and technology.

Responses (4)

Write a response