We need to hide/show some page elements based on if a slot is populated or not. Is there a way to determine if a slot is populated?
#macro(slotHasItems $slotname $hasItems)##
#initslot($slotname $params)##
#if($sys.currentslot.slot)##
#if($sys.currentslot.relresults.size() > 0)##
#set($hasItems="true")##
#else##
#set($hasItems="false")##
#end## if $sys..size()
#end## if $sys.current...
#endslot($slotname)##
#end##
In looking back at the code, I would modify the $params to have “max_results=1” (probably something like #set($params.max_results = 1), because really, you only need to figure out if the slot has at least one item (you don’t need to know how many) and getting one result back would be a lot faster…
If you have the PSO toolkit installed, you could probably use $user.psoSlotTools.getSlotContents.
Thank you very much for your response. Since we have recently installed the PSO toolkit, that’s likely the route we’d like to take so I’ve looked into getSlotContents() as you suggested. It certainly looks like that would fit our needs. Unfortunatly, I’m afraid I’m still fairly new to development in this system and with Java in particular. So I feel I’m a bit out of my depth here. What I envision is something like this:
#set($slotIsEmpty = $user.psoSlotTools.getSlotContents($assembly_item, "slotName", $map).isEmpty())
I’m primarily having difficulty specifying the parameters, particularly $assembly_item and $map though the “slotName” value seems pretty straight forward. Would you have any input on how to specify those parameters (and how to implement this in general, if for some reason what I’ve specified is significantly off-base)?
Set a binding in the template containing the slot thus:
$slotCountInt = $user.psoSlotTools.getSlotContents($sys.assemblyItem,'nameOfMySlot',$params).size()
…which will return an integer. In a subsequent binding, or back out there in your template, you can test, e.g:
#if ($slotCountInt == 0)
nothing to see here...
#end
Chris,
Thanks for helping move this forward. Unfortunately, I must be doing something wrong because the system returns an error when I attempt to implement. The error is as follows:
Unexpected exception while assembling one or more items: Problem when evaluating expression “$user.psoSlotTools.getSlotContents($sys.assemblyItem,‘[slotName]’,$sys.params).size();” for variable “$slotCountInt”: Could not find method getSlotContents for object [null] and arguments […
Aside from populating the actual slot name I only changed the “$params” value from your original code (changed to $sys.params). Initially, I tried implementing with $params as the value but that returned an error as well and populated the $slotCountInt with null.
From the error it would seem that either the system can’t find getSlotContents() or I’ve specified the parameters incorrectly. Would you have any further input on what I am doing wrong?