Expand my Community achievements bar.

SOLVED

Variations of Content Fragment in my custom component

Avatar

Employee

Hi, I have a custom component. I have a path field inside it's dialog. If I enter the path of content fragment I want to have a drop down that populates all its variations. Could you tell me how I do this?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @sakethchandra02 

This can be achieved via calling the servlet if the CF will be having different variations or by using the datasource for the fixed set of the variations.

Approach I:

You can create datasource node structure with sling:resourceType of datasource as sling:resourceType (String) = /bin/dropdownList ( i.e. Path of the servlet implementing the data source for dynamic value). It will give the desire result of a dynamic dropdown as you can see below the screenshot.

Shailesh_Bassi__0-1693150908197.jpeg

 

 

    

Shailesh_Bassi__1-1693150908202.jpeg

 

 

For DataSource Servlet (/bin/dropdownList) Implementation you can refer to below articles:

https://redquark.org/aem/day-17-granite-datasources/ 

http://www.sgaemsolutions.com/2019/01/dynamically-populate-drop-down-values.html 

 

Approach II:

You can create a listener for the adding the variation in a fixed list maintained at a fixed path e.g. /etc/variationList or /var/variationList. The dataSource will read the node and display the list.

 

I have not tried but thinking you can fix the CF folder parent path, if there are little variation of the variation List based on the folder path of the CFs. And this property can be fetched from one of the node property and this way it will be more dynamic as well.

 

Hope this helps

Thanks

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @sakethchandra02,

I think you can use dam/cfm/components/cfpicker which is dedicated widget for content fragment in combination with granite/ui/components/coral/foundation/form/select.

You can find working example of above in Content Fragment from Core components:

You should be able to adapt above solution in your custom component.

Avatar

Community Advisor

@sakethchandra02 I haven't tried this but you can try out the following approach.

 

https://jimfrenette.com/aem/components/dialog-coral-ui-select-cascade/

 

 

 

Avatar

Community Advisor

This is a very old article but you will get an idea about to fetch variation in the custom dialog

https://aemlab.blogspot.com/2018/09/aem-content-fragment-with-component.html 



Arun Patidar

Avatar

Correct answer by
Community Advisor

Hi @sakethchandra02 

This can be achieved via calling the servlet if the CF will be having different variations or by using the datasource for the fixed set of the variations.

Approach I:

You can create datasource node structure with sling:resourceType of datasource as sling:resourceType (String) = /bin/dropdownList ( i.e. Path of the servlet implementing the data source for dynamic value). It will give the desire result of a dynamic dropdown as you can see below the screenshot.

Shailesh_Bassi__0-1693150908197.jpeg

 

 

    

Shailesh_Bassi__1-1693150908202.jpeg

 

 

For DataSource Servlet (/bin/dropdownList) Implementation you can refer to below articles:

https://redquark.org/aem/day-17-granite-datasources/ 

http://www.sgaemsolutions.com/2019/01/dynamically-populate-drop-down-values.html 

 

Approach II:

You can create a listener for the adding the variation in a fixed list maintained at a fixed path e.g. /etc/variationList or /var/variationList. The dataSource will read the node and display the list.

 

I have not tried but thinking you can fix the CF folder parent path, if there are little variation of the variation List based on the folder path of the CFs. And this property can be fetched from one of the node property and this way it will be more dynamic as well.

 

Hope this helps

Thanks