Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

Count of Number of times component is reused in a page

preethamk694748
Level 3
Level 3

Hi Team. I have a requirement where  i need to have the count of number of times a component is dragged and dropped in a page

Suppose i have a link component and its dialog has a field(say analytics-field)

If i drag and drop component for first time in a page, that analytics-field in link component dialog should be auto-populated with value "Link1"

If i drag and drop component for second time in a page, that analytics-field in link component dialog should be auto-populated with value "Link2"

If i drag and drop component for third time in a page, that analytics-field in link component dialog should be auto-populated with value "Link3"

.

.

.

.If i drag and drop component for nth time in a page, that analytics-field in link component dialog should be auto-populated with value "Linkn"

Any way to achieve this,

Thanks

6 Replies
Veena_Vikram
Community Advisor
Community Advisor

Hi Preetham

     As far as I could understand , this can be achieved only via a custom logic in the back-end. Write a sling model for your component, and in the init method write the query to check the count of the component (Using query builder API, find the component count ) in current-page and  for each count using Properties API and Node set the value of the property you want to manipulate

Below predicates might help

path = <current page path>

type = "nt:unstructured"

resourceType=< relative path of your component> (never start from /apps)

p.limit=-1

Thanks

Veena

preethamk694748
Level 3
Level 3

Thanks Veena, Will try this and ill come back if im stuck or if i have any doubts

mjb54261515
Level 5
Level 5

This can be achived only with custom logic. There is no particular API to return number of counts.

  • use node iteration logic for jcr node of page path.
  • from there you can compare each node resource Type to your component resource path. it matches then counter+
  • by the end of iteration logic you will have number of times component is used on the page.

preethamk694748
Level 3
Level 3

Thanks Bro, Will try and come back to you if im stuck somewhere