Get transformation item count in macro

David Kir asked on June 12, 2017 15:39

New to Kentico... how can I get a count of items that are pulled into a transformation in a separate web part on the same page?

The transformation in this case is named CarouselItems, and I need to know how many items are there.

{% CurrentDocument.DocumentContent["CarouselItems.Count"] #%}

Thanks!

Recent Answers


Trevor Fayas answered on June 13, 2017 00:18

For the most part, there isn't a default way to grab another web part's information or count. What you can do however (although it will depend greatly on the first repeater rendering first, so make sure it's higher on the page template) is you can use Kentico's API to set a macro value. Use an custom macro method or custom transformation method to send the DataItemCount to the following call:

CMS.MacroEngine.MacroContext.CurrentResolver.SetNamedSourceData("MyCustomCarouselCount", TheNumber);

As long as the above runs before your other one, you should now be able to get the number through the macro

{% MyCustomCarouselCount %}

However i would ask...why do you need the count, there may be an easier way to do what you want to do.

0 votesVote for this answer Mark as a Correct answer

David Kir answered on June 13, 2017 20:12

Thanks Trevor -

The transformation is in a web part which is an image carousel... I just need to know if there are any images present so that I can draw a navigation anchor to the carousel in the top section of the page.

0 votesVote for this answer Mark as a Correct answer

Development Support Avastonetech answered on June 14, 2017 04:38 (last edited on June 14, 2017 04:38)

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on June 14, 2017 04:39

Sometimes what i do if i need to have something like an image carousel and have a navigation, is to simply duplicate the repeater and make the 2nd one the navigation. You can use the transformation "IsFirst()" to display only on the first element, then use the DataItemCount from it. Try that!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.