I'm looking for idea how to render page with existing components by using content from either content fragments or some external content
We don't like to build giant component to render this content but rather reuse existing components like headers, text, image etc.
To do this I wonder if we can somehow inject content from CF formatted into correct structure into page JCR so Sling rendering will think it is real JCR content and will use existing components to render it?
I think you can achieve what you need in 2 ways:
1. Client side: You use AJAX to get the "content" (data) from another resource (can be from JCR or others) and through js, you will render your component.
2. Server side: You point your sling model to use the information from somewhere else in the JCR.
Also, keep in mind that you could embed components to avoid creating "huge" components, you can refer to this https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#229-resource to learn more about how to do it.
it is something I try to avoid to modify components as first we have many of them and second we may have multiple different source of data. So having one "injector" will make it more flexible and potentially simpler
@broman_pl Thanks for sharing the interested use-case.
AEM has a concept of Synthetic Resource https://developer.adobe.com/experience-manager/reference-materials/6-4/javadoc/org/apache/sling/api/...
There is a sample available at: https://github.com/Adobe-Consulting-Services/acs-aem-samples/blob/master/core/src/main/java/com/adob...
I haven't tried myself. Please let us know, if it helps
I would recommend you to check Content Fragments and Experience Fragments. These are ootb features which allow you to reuse content.
Content fragments are one of potential source of data. But I try to find flexible way of rendering content from them without need to create very specific components and models for rendering on server side. One of example is need to duplicate some elements base on content. For example if I need to display list of CF in format based on set of components. My ideal solution will be to be able to say in java model base on this sling resource type and data in json give me html output. So far I don't have good solution for displaying list of content fragments without creating very specific component for this purpose only. Only idea that I can think about is java filter that is taking html output of page where I have handlebars placeholders and fill it with this structured content. This way I can give authors ability to build flexible set of components to fill with data but wonder if there is a better way of doing this
I still don't get your requirement in detail. I understand that you want to take existing data and embed it in a flexible way in existing components (using placeholders?). Something similar to Contextual Content Variables (CCVar) of ACS AEM Commons [1]?