In cross site links, site id not correct in assembly Item clone

Here is the simple structure

Site A:

  • CT_1_Item1
    – slotA
    —CT_2_Item1

Site B:

  • CT_3_Item1
    –slotB
    — CT_1_Item1

What I want to do is to generate a valid url to CT_2_Item1 from Site B on the full page template of CT_3_Item1. I am doing this on a velocity macro on CT_3’s full page template. Everything is almost working, except it thinks that CT_2_Item1 is on Site B. The link to CT_1_Item1 is however correct.

After some trial and error, i realized that the when setting the node after $sys.assemblyItem.clone(), the cloned assemblyItem does NOT have the correct siteid set.

A simple test with a cross site link confirmed this:


initslot("mySlot"  "")
#if($sys.currentslot.relresults.size() > 0)
#set($relresult = $sys.currentslot.relresults.get(0))
#set($test = $sys.assemblyItem.clone())
$test.setNode($relresult.getNode())##
$relresult.getSiteId()
$test.getSiteId()
#end## $sys.currentslot
#endslot("mySlot")	

I expected $relresult.getSiteId() to equal $test.getSiteId() but that is not the case. Is this the correct behavior or is it a bug? I would have assumed that when you set the node, that the site id would also be set to that node’s site id (ie it could be one of the property values of the node), but clearly I am mistaken.

BTW, I can get around my problem by passing the $relresult around my macros to generate the correct url, but I just thought that the above was an unexpected behavior.

On further thought, I guess this would be expected behavior because the node is the object in question and thus would not have any site information associated with it (as it could be in multiple sites). So in cloning the assemblyItem, I am effectively cloning the site information then by setting the node, I am saying that the node exists in that site…whether it really does so or not.

Jit,

Your analysis (in the second post) is correct. By setting the node, you are just replacing the node itself. All other information (site, context, folder, etc) remains the same.

Dave