number of items in a slot

Hi

I’d like to count of the number of items in a slot before the slot has initialised. I though using something like this would work:

$user.psoSlotTools.getSlotContents($sys.assemblyItem,"MySlot").relresults.size()

or

$user.psoSlotTools.getSlotContents($sys.assemblyItem,"MySlot").size()

but get the this error

Could not find method getSlotContents for object

Any Clues?

Cheers
James

James,

JEXL is very particular about the number of arguments for a function.

if a function is defined with 3 arguments, you have to give it 3 arguments, or you get the cryptic error message. The types have to match as well.

Dave

A sort of roundabout way of doing this, but you could create a macro that returns the $sys.currentslot.relresults.size(). Of course, this still initializes the slot :frowning:

Ie.


#macro (numslotitems $slotname $params $numitems)
  #initslot($slotname $params)	
    #if ($sys.part.render)
      #if($sys.currentslot.slot)
        #set($numitems = $sys.currentslot.relresults.size())
      #end
    #end
  #end ($slotname)
#end

The difference between #initSlot and psoSlotTools, is that psoSlotTools creates the new Assembly Items, but stops one step short of actually assembling the items.

If the items in question are small snippets (links, etc), then the difference between the 2 is pretty minimal. I think Jitendra’s method is probably superior in this case. If the templates are really large and complex (or have slot on them), then you might save something by not assembling them.

Dave

A small correction to Jitendra’s very useful code…

#macro (numslotitems $slotname $params $numitems)
  #initslot($slotname $params)	
    #if ($sys.part.render)
      #if($sys.currentslot.slot)
        #set($numitems = $sys.currentslot.relresults.size())
      #end
    #end
  #endslot($slotname)
#end

A small correction to Jitendra’s very useful code…

#macro (numslotitems $slotname $params $numitems)
  #initslot($slotname $params)	
    #if ($sys.part.render)
      #if($sys.currentslot.slot)
        #set($numitems = $sys.currentslot.relresults.size())
      #end
    #end
  #endslot($slotname)
#end

[QUOTE=jimbo;1227]Hi

I’d like to count of the number of items in a slot before the slot has initialised. I though using something like this would work:

$user.psoSlotTools.getSlotContents($sys.assemblyItem,"MySlot").relresults.size()

or

$user.psoSlotTools.getSlotContents($sys.assemblyItem,"MySlot").size()

but get the this error

Could not find method getSlotContents for object

Any Clues?

Cheers
James[/QUOTE]

The macro method mentioned here is interesting, but I’d rather count the slot contents in the bindings. I’ve tried every variation of the above code I can think of and get nothing but cryptic errors. What would the correct syntax be?

Here are examples of what I’ve tried:
$user.psoSlotTools.getSlotContents($sys.assemblyItem, “slotName”, “”).size
$user.psoSlotTools.getSlotContents($sys.assemblyItem, “slotName”, “”).size()
$user.psoSlotTools.getSlotContents($sys.assemblyItem, “slotName”, “template=templateName”).size
$user.psoSlotTools.getSlotContents($sys.assemblyItem, “slotName”, “template=templateName”).empty
$user.psoSlotTools.getSlotContents($sys.assemblyItem, “slotName”, “template=templateName”).isEmpty()
etc.

I’m pulling my hair out. This is my first big project using Percussion CM System. Is there any documentation for the psoSlotTools, or something akin to Javadoc for these methods?

Hi Daniel

Use this in the bindings:

$user.psoSlotTools.getSlotContents($sys.assemblyItem,'yourslotname',$params).size()

The params variable is still needed even if you’re not using it.

Cheers
James

A heads up for other less experienced users like me: Jitendra’s numslotitems macro creates problems with Active Assembly.

I used the macro and the slot on the same page (the number of items in the slot is used to help format the contents of the slot, e.g. to divide into two equal columns). In Active Assembly, trying to add or remove items from the slot generates an index out of bounds exception, and prevents the page from refreshing automatically. According to Alex in tech support, there were two problems:

The issue is primarily caused by the fccc_numslotitems macro. The macro is not properly written/marked for page active assembly. If you intend to use this macro for active assembly, it will need to be re-implemented.

Same slot twice on a page. Solution: Make only one instance of that slot as Active Assembly.

I replaced the macro with jimbo’s psoSlotTools code in the bindings, and now Active Assembly is happy.