I am looking to create a custom component to pull content fragments based on type(content fragment model) and/or a field filter. Wondering if anyone from the community has already created such types of components. If yes, could you please share the link?
Thanks.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi
You can utilize the Query builder concept for searching any type of data in your custom code and write query on the fragment type with path as your root cf path
For more information on query builder please follow this article
Hi
You can utilize the Query builder concept for searching any type of data in your custom code and write query on the fragment type with path as your root cf path
For more information on query builder please follow this article
Below blog shows exactly how to query the fragments using query builder based on model. Please check it out,
https://aemsimplifiedbynikhil.wordpress.com/2020/10/11/content-fragment-as-java-apis/
Map<String, String> map = new HashMap<>(); map.put("type", "dam:Asset"); map.put("path", "/content/dam"); map.put("First_property", "jcr:content/contentFragment"); map.put("First_property.value", "true"); map.put("Second_property", "jcr:content/data/cq:model"); map.put("Second_property.value", "conf/fragmentexamples/settings/dam/cfm/models/<your-model-name>"); map.put("property.and", "true"); map.put("p.limit", "-1"); QueryBuilder queryBuilder = request.getResourceResolver().adaptTo(QueryBuilder.class); Query query = queryBuilder.createQuery(PredicateGroup.create(map), request.getResourceResolver().adaptTo(Session.class)); final SearchResult result = query.getResult();
@MukeshAEM mostly this can be achieved with Query Builder as pointed by answers below.
But in case of Content Fragments, I personally prefer using GraphQL, which will optimize and would prove to be a better solution in case Content Fragments and Content Fragment Models scale to a larger number. It could also prove to be a better option, if the component requirement get more complex and asks for even more complex queries. Please refer below link to achieve your usecase:
https://github.com/adobe/aem-headless-client-java
Views
Likes
Replies
Views
Like
Replies