Expand my Community achievements bar.

SOLVED

Diiferent exporters for different content fragment models

Avatar

Level 5

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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)

 

Solved: Model exporter xml - how customize response conten... - Adobe Experience League Community - ...

View solution in original post

4 Replies

Avatar

Community Advisor

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:

http://localhost:4502/api/assets/we-retail/en/experiences/48-hours-of-wilderness/48-hours-of-wildern...

 

Refer:

https://experienceleague.adobe.com/docs/experience-manager-65/assets/extending/assets-api-content-fr...

 

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

Avatar

Community Advisor

@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. 

Avatar

Level 5

@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.

Avatar

Correct answer by
Community Advisor

@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)

 

Solved: Model exporter xml - how customize response conten... - Adobe Experience League Community - ...