Getting the current item in a navigation template

Hi,
I’m working on our new web site to manage the navigation. We have a multilingual site and in my top navigation I need to retrieve my current item to insert link to its translated item (if we are browsing in English and my page is translated in French, I want to have a link to get directly to this page in French in the Top Nav). When I try to get property of my item, I always capture the property of the Navon.
Can I still access an item within a navigation template ?

The easiest way to do this is to define a variable in the bindings tab of the parent page template. Give it a name like $myparentpage. It’s legal for this to have multiple values, for example $myparentpage.node (for the content node) and $myparentpage.linktofrench and $myparentpage.linktoenglish for links, etc.

If you set these values in the bindings JEXL, they will accessible in the Navon template.

Be careful to check that the values exist by using #if($myparentpage) in your top nav template before referencing them. These values won’t be present when you preview the topnav template by itself, only when the top nav template is assembled into a page.

I hope this helps.

Dave

Hi Dave,
Thanks for the post. I can now access my current item from my navigation template.
I’m now trying to get my translated item from my current item but don’t know how to get it. Can you help me on this one too ?

Regards,

Guillaume

Guillaume,

This one is a little tougher. What you really need is a new kind of “autoslot” that populates with the translation of the current item (or the item that the current item is a translation of).

I would do this by creating a new slot content finder (as a Java extension), but this maybe a bit too difficult for most people. Unfortunately, I don’t have one pre-built.

It’s probably also possible with just a SQL statement, although this is somewhat riskier than using the Java API.

Dave

The sys_TranslationContentFinder should do the trick for you. This Content Finder returns the list of Content Items associated in a Translation Relationship with the Content Item being assembled.

I should point out that the translation finder finds content in ALL locales, not a specific locale.

If you have more than 2 languages, you’ll need to filter the results that come back from this to a specific locale.

Guillaume, do you just have French and English, or are there other languages as well ?

Dave

Hi,

We have 3 locale, French, English ans Spanish. I’m now abble to get my translation from my page template, I’m now trying to get it from my Nav Template but it is not working yet. Is there’s a way to find the site id associate to a page ? The only site id I can get now is the one in the site I am.
My url are not good either. The site id in the url are not changing from one site id to another so all my navigation is not following when I click on the link.

Thanks for all your help.

Guillaume

I don’t see any way to pass the siteid in the current code.

Do you know the site (i.e. is it always the same site), or do we need to determine it on the fly?

Dave

I have 3 sites, one for each locale. The problem is that I’m not sure I can determine in witch site I am with the locale of the item. A user could, by mistake, create an English item in the French site per example.

Guillaume

Guillaume,

I’ve done a little more research, and talked to a couple of the guys here. We don’t see any way to do what you need without at least a little Java code.

First, you need to get the GUID of the Site. Because an Item can be in more than one site at a time, there’s no foolproof way to obtain the site from just the item id. You can look at what folder paths it is in, you can use the locale, and maybe a few other ways. As you point out, somebody could create content in the “wrong” site or locale, and then the links would be broken.

To get the GUID of the site, you must either have the site id, or the site name. If you have the name, call IPSSiteManager.findSiteByName(name).getGUID(). If you have the id, you can call IPSGuidManager.makeGuid(id,PSTypeEnum.SITE). In either case, you must write a small Java function to do this.

Once you have the Site GUID, there are 2 basic approaches to the problem:

  1. Write your own subclass of PSTranslationSlotFinder, pass the Site GUID as a parameter, and have your subclass populate the SlotItems that it creates with the Site GUID, by calling SlotItem.setSiteId()

  2. Modify the slot macros, so that in the “initslot” macro you have the following:


#set($transItem = $sys.assemblyItem.clone())
$transItem.setSiteId($siteGuid) 
#set($sys.currentslot.relresults = $rx.asmhelper.assemble($transItem,$sys.currentslot.slot,$completeparams))

When the slot is assembled, the links will point to the site identified by $siteGuid.

We suspect that since you have write some Java code anyway, you might be better off with the new ContentSlotFinder approach, as it has less impact on the macros, and things like “Active Assembly” are not impacted.

Dave

Hi,
Thanks for the help. I’m trying to modify the macro “#inislot” as you suggest but I can’t find a way to call the “IPSGuidManager.makeGuid(id,PSTypeEnum.SITE)” you suggest. Here is my code for now

#macro(initslot $slotname $params)##
#__renderpartstart($slotname 'slot')##
#__slotsetup($slotname $params)##
#if ($sys.currentslot.slot)##
#set($sys.currentslot.active = $sys.activeAssembly && $sys.currentslot.isrelationshipfinder)##
###set($sys.currentslot.relresults = $rx.asmhelper.assemble($sys.assemblyItem,$sys.currentslot.slot,$completeparams))##
#set($transItem = $sys.assemblyItem.clone())##
#if($transItem.node.getProperty("sys_lang")=="fr-ca")
	#set($siteGuid = IPSGuidManager.makeGuid("305",PSTypeEnum.SITE))
#elseif($transItem.node.getProperty("sys_lang")=="en-us"
	#set($siteGuid = IPSGuidManager.makeGuid("306",PSTypeEnum.SITE))
#else
	#set($siteGuid = IPSGuidManager.makeGuid("307",PSTypeEnum.SITE))
#end
$transItem.setSiteId($siteGuid)##
#set($sys.currentslot.relresults = $rx.asmhelper.assemble($transItem,$sys.currentslot.slot,$completeparams))##
#end##
#end

How can I fix this ?

Thanks,

Guillaume