Counting number of items in another item's slot

This seems to work on 6.5.2 (if you have a sufficiently recent PSO Toolkit installed)…

$user.psoSlotTools.getSlotContents($sys.assemblyItem,"__NAME_OF_SLOT__",$rx.string.stringToMap("template='__NAME_OF_TEMPLATE__'")).size(

The name of the slot and the name of the template used to assemble items in that slot must be filled in. I have just created a blank snippet template, assoicated with no content types or sites, called cmsSnJustForCounting, which seems to work as well as any “real” template, at least in preview. I have yet to test it when publishing.

Can anyone see any reason why we shouldn’t start using this to check if slots have been populated, and if so with how many items? An example of where this might be usefuly is to decide whether to output a hyperlink to another version of the same page, using a different page template which then actually displays the list of items in the slot.

The title of this thread is perhaps a little misleading. The above will count items in the specified slot of the item currently being assembled. I guess you could use it to find the number of items in a different item’s slots by cloning the assembly item then setNode()ing it to a different item.

This only works when using $user.psoSlotTools.getSlotContents. If you use something like #initslot then the template must be associated/allowed for all content types you wish to count.