Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Content Fragment as Java APIs | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

Content Fragment as Java APIs by AEM Queries & Solutions

Abstract

In this article we will go through different APIs of content fragment which we can use while exposing or customizing the behavior of CF.
To start with lets understand how we get the related content fragment of a specific model using a query builder.

First we start with adding the specific properties to the map and running a query:

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/");
map.put("property.and", "true");
map.put("p.limit", "-1");

Once we are done creating the map we will create our query variable using the request:

QueryBuilder queryBuilder = request.getResourceResolver().adaptTo(QueryBuilder.class);

Now we will get the results using query and the map using Predicategroup:

Query query = queryBuilder.createQuery(PredicateGroup.create(map),
request.getResourceResolver().adaptTo(Session.class));
final SearchResult result = query.getResult();

This result variable will hold all the Content fragment used by the specified content model at location /content/dam(we defined while creating the map).

Now we can iterate on the results and get the specified resource and adapt it to ContentFragment interface which holds all the content fragment related APIs.

Read Full Blog

Content Fragment as Java APIs

Q&A

Please use this thread to ask the related questions.



Kautuk Sahni
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

0 Replies