A client wanted a site that should have content in Norwegian, English and French. In the design file there was separate choises for the three different languages, and then a navigation area, where the navigation should be in the currently selected language.
This could be solved in different ways. One could make three different page templates calling the three different language navigations - or one could make categories for each of the languages and make pages belong to one of these.
However we wanted to have only one template, and not to have categories. We wanted to sort it with three different top nodes in the site tree. Looking like this:
Then we gave aliases to these three navigation nodes.
We then made a new method in a utilities cfc we use in our company, and call it like this from out header template (before the navigation section):
<cfinvoke component="farcry.idlmedia_core.utilities" method="searchForParentAlias" returnvariable="parentAlias">
<cfinvokeargument name="objectID" value="#request.navid#">
<cfinvokeargument name="aliases" value="home,engelsk,fransk">
</cfinvoke>
The method then checks if the current page, or any of it's ancestors have an alias of one of those provided with the cfinvokeargument. It then returns the alias, and we can make the navigation like so:
<skin:genericNav navID="#application.navid[parentAlias]#"
id="nav"
depth="2"
bActive="true"
bIncludeHome="false">
Here's the code for the method (first version - it still needs some work):
<cffunction name="searchForParentAlias" access="public" returntype="any" hint="searches up the navigation tree for a node with alias from argument.aliases">
<cfargument name="objectID" hint="Navigation ObjectID" type="uuid" required="yes" />
<cfargument name="aliases" required="yes" type="string" hint="list of aliases to search for">
<cfset qAncestors = request.factory.oTree.getAncestors(objectid=arguments.objectid)>
<cfset listAncestors = QuotedValueList(qAncestors.objectid)>
<cfset listAncestors = ListAppend(listAncestors,"'#arguments.objectid#'")>
<cfloop list="#arguments.aliases#" index="i">
<cfset thisaliasid = application.navid[i]>
<cfif ListFind(listAncestors, "'#thisaliasid#'")>
<cfset foundParentAlias = i>
</cfif>
</cfloop>
<cfreturn foundParentAlias>
</cffunction>
By doing it this way we have a reusable way of handling this, without the hassle of managing several very similar templates, and with a very intuitive grouping of the different articles in the site tree.