for each item in slot loop

Is there a way you can create a loop for each item in a slot?

And

check to see if slot contains items?

To check if the slot contains any items, then loop through all the items:


#initslot("erauLandingImage" "")##
#if($sys.currentslot.relresults.size() > 0)##
     #foreach($myChild in $sys.currentslot)##
          (slot item here)
     #end##
#end##

I have got a similar situation. I am able to loop thru the slot…For each child item in the foreach…I need to access data from the child’s slot…How do I run a nested loop that? Or is there anyway to get data from the child’s slot?

Could you clarify the data you are wanting to access? Thus far, I have:

[ol]
[li][Content Item A][/li][ul]
[li]Slot A[/li][LIST]
[li]Snippet 1[/li][LIST]
[li]Field Data[/li][/ul]

[li]Snippet 2[/li][ul]
[li]Field Data[/li][/ul]
[/ol]
[/LIST]
[/LIST]
You are wanting to access Slot A snippets’ Field Data or Slot A snippets’ slot?

It becomes a bit confusing.

I am trying to access Snippet items slot item…
So it will be like this:
1.[GrandParentContent Item A]

                       •Slot A
                             •Snippet 1 xchild1
                                         Slot xchild
                                              Snippet child

Also let me try to explain again here:
Say you have a page content type, that has a slot for an image content type content item. Now the the Image content type has a slot for a link content type content item. In my page template, if I use the foreach loop, I can easily access the Image content item which is in the Image slot of the page. And also I can easily access any field properties. However, my challenge is to access the Link content item which is in the slot of the Image content type…

Is this clear…

thanks
Manvinder

Gotcha, let me see what I can find in our environment that matches your situation.

Manvinder,

We have one case where we call


#slot("slotName" "header" "before" "after" "footer" "params")##

Then in the default snippet template we call


#initslot("linkSlot" "")## Contains the content item to be linked to the image
#if($sys.currentslot.relresults.size() > 0)## Only create link if slot is populated
#set($item = $sys.currentslot.relresults.get(0))## We only need one item from this slot
#set($link = $rx.location.generate($item))##Generate location and assign to $link
#end##

We can test $link to see if it is populated, and attach a

<a>

tag around our image element if needed.

Was there a specific need to do all of this in one template instead of relying on multiple templates?

I would also look at the following macro #__slotsetup($slotname $params)## and possibly $assemblyItem.clone($aclone) and $aclone.setNode()…

Based upon jitendra’s recommendation, try the following:

#initslot("slotName" "")## Set up slot to retrieve content items
#if($sys.part.render)##
#if($sys.currentslot.slot)##
#foreach($relresult in $sys.currentslot.relresults)##
#__slotsetup("childSlotName" "")## Set up child slot to retrieve content items
#set($item = $sys.assemblyItem.clone())##
$item.setNode($relresult.getNode())##
#set($sys.currentslot.relresults = $rx.asmhelper.assemble($item,$sys.currentslot.slot,$completeparams))##
#if($sys.currentslot.relresults.size() > 0)##
#foreach( $relresult in $sys.currentslot.relresults )##
$relresult.getNode().getProperty('rx:sys_title').String ## Data from the child slot content items.
#end##
#end##
#end##
#end##
#end##

Thanks Riley and Jitendra…I will try these solutions.
With multiple templates, it would have been simple, but we are restricted by the client on the number of templates that we can create, so trying to minimize them.