Diiferent exporters for different content fragment models | Community
Skip to main content
Level 4
April 13, 2022
Solved

Diiferent exporters for different content fragment models

  • April 13, 2022
  • 2 replies
  • 986 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Nitin_laad

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

2 replies

RajaShankar
Community Advisor
Community Advisor
April 13, 2022

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-wilderness.json

 

Refer:

https://experienceleague.adobe.com/docs/experience-manager-65/assets/extending/assets-api-content-fragments.html?lang=en

 

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

Nitin_laad
Community Advisor
Community Advisor
April 13, 2022

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

asn11Author
Level 4
April 14, 2022

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

Nitin_laad
Community Advisor
Nitin_laadCommunity AdvisorAccepted solution
Community Advisor
April 14, 2022

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