Hi @ssin93 ,
To achieve the functionality you described, where you want to compare a field value from a content fragment with the values in a multifield of a component and display them in a specific order on the page, you'll need to follow these general steps:
Create the Content Fragment:
- Define a content fragment model with the necessary fields, including the one containing the card name.
- Create content fragments using this model and populate the card name field.
Create the Component:
- Design a component with a multifield to store multiple values.
- Each item in the multifield should have a field to store the card name.
Populate the Multifield:
- Populate the multifield of the component with card names as per your requirement.
Order the Multifield Items:
- Define the order of the items in the multifield. This can be achieved by manually arranging them or by adding a specific order field to each multifield item.
Compare and Display:
- In your page template or component logic, retrieve the content fragment and its card name field value.
- Retrieve the multifield values from the component.
- Compare the card name from the content fragment with the values in the multifield.
- Based on the comparison result and the defined order, display the items on the page.
Here's a simplified example of how you might implement the comparison and ordering logic in a Java servlet (assuming you're using AEM with Java development):
// Assume cfCardName is the card name field in the content fragment
String cfCardName = contentFragment.getProperty("cfCardName", String.class);
// Assume multifieldValues is a list of card names from the component's multifield
List<String> multifieldValues = new ArrayList<>();
for (Resource item : multifieldResource.getChildren()) {
String cardName = item.getValueMap().get("cardName", String.class);
multifieldValues.add(cardName);
}
// Compare cfCardName with multifieldValues and order accordingly
Collections.sort(multifieldValues, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
// Implement comparison logic here based on your requirements
// For example, you might compare based on alphabetical order
return o1.compareTo(o2);
}
});
// Now multifieldValues list contains card names in the desired order
This is a simplified example and may need to be adapted based on your specific implementation details and requirements. You'll need to integrate this logic into your AEM project, considering the appropriate APIs and data models you're using. Additionally, you might need to handle error cases and edge conditions in your implementation.