Extend Experience fragments of core using delegation pattern
Hello Members,
We are trying to extend Core Experience fragment to meet our client needs where each page can have its own header and footer.
The approach we are trying now is to unlock the experience fragment in the structure so that the author can configure per page which works fine.
However, on top of this we need same Experience fragment header to be set for all the child pages below . I am using Delegate pattern for the same and unfortunately this seems to not work .
Note: We are using aem-react-editable-components so the mapping happens in import-component.js and not the usual way with html.

Below is my Implementation
@Model(adaptables = { Resource.class,
SlingHttpServletRequest.class }, adapters = { ExperienceFragment.class }, resourceType = CustomExperienceFragmentImpl.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
@Getter
public class CustomExperienceFragmentImpl implements ExperienceFragment {
protected static final String RESOURCE_TYPE = "myproject/components/core/experiencefragment";
@Self
@Getter(AccessLevel.NONE)
private SlingHttpServletRequest request;
private String fragmentVariationPath;
@PostConstruct
void init() {
InheritanceValueMap properties = new HierarchyNodeInheritanceValueMap(request.getResource());
fragmentVariationPath = properties.getInherited(ExperienceFragment.PN_FRAGMENT_VARIATION_PATH, String.class);
}
@Self // Indicates that we are resolving the current resource
@Getter(AccessLevel.NONE)
@Via(type = ResourceSuperType.class) // Resolve not as this model, but as the model of our supertype (ie: CC Image)
@Delegate(excludes = DelegationExclusion.class) // Delegate all our methods to the CC Image except those defined below
private ExperienceFragment delegate;
@Override
public String getLocalizedFragmentVariationPath() {
return fragmentVariationPath!=null ? fragmentVariationPath : delegate.getLocalizedFragmentVariationPath();
}
private interface DelegationExclusion {
String getLocalizedFragmentVariationPath(); // Override the method which determines the source of the asset
}
}
Kindly share your views
Thanks
Arun