Can we create different exporters for different content fragment models, just the same way we would create for different components.
meaning a content fragment model (article) would export only 2 fields when its put on a page (and accessed via page.model.json)
and another content fragment model (eg banner) would export may be 4 fields when its put on a page(and accessed via page.model.json)
Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
@asn11Assuming that you have already explored GraphQL API, and it doesn't fit your requirements.
You can write your own custom model exporter via extending ModelExporter, customize page.model.json as you need in order to return it to an external API.
ref -
ModelExporter (Apache Sling 12 API)
Hi @asn11
You can access content fragment diectly as json using asset API no need to associate it with a page to view the json of CF.
Sample:
Refer:
If you want to expose only specific fields inside the CF json use framework like graphql api to filter and expose only required fields on top of asset api.
Regards,
Rajashankar.R
@asn11 I am not getting your actual use case, but you should be able to achieve this using JSON exporter and custom selectors -
Enabling JSON Export for a Component | Adobe Experience Manager
Or
You should explore the use of GraphQL as well.
@Nitin_laad Use case is , that we'd have a headless setup in which we'd only have page composed from number of content fragments only. so think a header CF , a footer cf and all other components as CFs only.
then we'd expose page model json for consumption to other app.
so here, I would have diff requirement for header CF export and different req for footer CF export.
Moreover, I may have CF referencing another CF inside, here the default exporter does not inline all the fields that a child CF has, in such cases I'd want to customize the exporter to control how the exporter would work at each CFM level.
hope that give idea.
@asn11Assuming that you have already explored GraphQL API, and it doesn't fit your requirements.
You can write your own custom model exporter via extending ModelExporter, customize page.model.json as you need in order to return it to an external API.
ref -
ModelExporter (Apache Sling 12 API)
Views
Likes
Replies
Views
Likes
Replies