Friday, November 17, 2017

Quick Tip: Count Child Items of Sitecore Tree using Google Chrome Dev Console

There have been several requests among different clients our practice works with to provide a simple count of items under a part of a Sitecore tree.

While writing a Sitecore query and running it against the XPath builder is completely feasible, there is a quicker way if you're just trying to get a child count.

Open up the Sitecore Content Editor, activate the node you want to get the number of children under and expand it.

Open up your Google Chrome Dev Console and run the following line of Javascript:

 document.getElementsByClassName('scContentTreeNodeActive')[0].nextSibling.childNodes.length  

This one-liner finds the active Content Tree node and discovers the number of child items living under it.



Note: This doesn't account for all descendants and only seems to work with Google Chrome, however, I've found this useful in a few situations now across any Sitecore version.

Enjoy!