Abstract
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
package com.aemks.core.transformers;
import org.apache.sling.rewriter.Transformer;
import org.apache.sling.rewriter.TransformerFactory;
import org.osgi.service.component.annotations.Component;
/**
* This link transformer factory is used to rewrite master links to live copy links
*/
@Component(
service = TransformerFactory.class,
property = {
"pipeline.type=referencelinkrewriter"
}
)
public class ReferenceLinkTransformerFactory implements TransformerFactory {
@Override public Transformer createTransformer() {
return new ReferenceLinkTransformer();
}
}
Read Full Blog
Q&A
Please use this thread to ask the related questions.
Kautuk Sahni