Hello Community,
Is there any setting in content fragments for filtering all non null values?
What i know is we can filter all non null at client side. I was looking for a setting where the server can filter and remove all null fields
Please let me know if any one has this done already
Thanks
Arun
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @arungm20,
There is a way around this but it is not the best approach. If you want to do the filtration on the server side you can use the Content Fragment API and check if the element exist and do a null check for the value.
Resource fragmentResource =resourceResolver.getResource(contentFragmentPath);
ContentFragment contentFragment=fragmentResource.adaptTo(ContentFragment.class);
ContentElement element = contentFragment.getElement(elementName);
if (null != element && null != element.getValue() && null != element.getValue().getValue()) {
//your logic
}
Create a model with all the fields(data members) as in content Fragment. In the dialog just give a pathfield to select the desired CF. You can make it a multifield incase you need a list of CF's to populate.
You can set the fields of the model depending on the non null values of CF as given in the code snippet and read the same in your htl(sightly).
This is just a way around if you need to filter non null values on server side.
Let me know if it suits your use case.
@arungm20 , You can filter if you're using GraphQL. Please check below.
https://experienceleague.adobe.com/docs/experience-cloud-kcs/kbarticles/KA-21792.html?lang=en
Thanks @Siva_Sogalapalli we did use this. However, when we have multiple null values the query would need to add filter for all the attributes and hence i was thinking if there is any setting in Content fragments where we can just strip out null values
Then you can try to add field validation at content fragment model itself like make it as required field but may not work if you want to make it as optional field.
Agree I have fragments which do not need the values
Hi @arungm20,
There is a way around this but it is not the best approach. If you want to do the filtration on the server side you can use the Content Fragment API and check if the element exist and do a null check for the value.
Resource fragmentResource =resourceResolver.getResource(contentFragmentPath);
ContentFragment contentFragment=fragmentResource.adaptTo(ContentFragment.class);
ContentElement element = contentFragment.getElement(elementName);
if (null != element && null != element.getValue() && null != element.getValue().getValue()) {
//your logic
}
Create a model with all the fields(data members) as in content Fragment. In the dialog just give a pathfield to select the desired CF. You can make it a multifield incase you need a list of CF's to populate.
You can set the fields of the model depending on the non null values of CF as given in the code snippet and read the same in your htl(sightly).
This is just a way around if you need to filter non null values on server side.
Let me know if it suits your use case.
Thanks @Madhur-Madan this approach i will keep in mind and use for other requirements. This seems like any other components and combining the CF
Views
Likes
Replies
Views
Likes
Replies
Views
Like
Replies