Highlighted

Count of Number of times component is reused in a page

Avatar

Avatar

preethamk694748

Avatar

preethamk694748

preethamk694748

30-10-2017

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

Replies

Highlighted

Avatar

Avatar

Veena_Vikram

MVP

Avatar

Veena_Vikram

MVP

Veena_Vikram
MVP

30-10-2017

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

Highlighted

Avatar

Avatar

mjb54261515

Avatar

mjb54261515

mjb54261515

30-10-2017

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.

Highlighted

Avatar

Avatar

preethamk694748

Avatar

preethamk694748

preethamk694748

30-10-2017

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

Highlighted

Avatar

Avatar

Veena_Vikram

MVP

Avatar

Veena_Vikram

MVP

Veena_Vikram
MVP

30-10-2017

Sure. Happy to help anytime. Let us know ..

Highlighted

Avatar

Avatar

preethamk694748

Avatar

preethamk694748

preethamk694748

30-10-2017

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

Highlighted

Avatar

Avatar

mjb54261515

Avatar

mjb54261515

mjb54261515

30-10-2017

Sure cheer. Let me know if ur stuck