#if ( $submenu ) .. not working correctly

Test site http://rmx.camagazine.com and you’ll see how the navigation should work (this is hard coded for now).

I’ve used the code from the FF snippets, modified as best I could (see below) but its getting stuck on the #if ( $submenu ) line. Basically if there is no second level then I do not want the <ul></ul> to happen, instead it should move to the next item but it doesn’t, it shows the <ul></ul> giving me a blank submenu.

From my understanding the if submenu is saying if submenu exists then do this, is that correct? What is my flaw here?

Shane

<ul id=“nav”>
#macro(rootlevel $node)

This template builds top image and starts the ULs

#set($submenu = $node.getNodes(“nav:submenu”))
#if ($node)
#foreach ($navon in $submenu)
#firstlevel ($navon)
#end
#end

#end

#macro(firstlevel $node)

this macro processes the first level navons

#set($title = $node.getProperty(“rx:displaytitle”).String)
#set($landing_page = $node.getProperty(“nav:url”).String)
#set($submenu = $node.getNodes(“nav:submenu”))
#set($axis = $node.getProperty(“nav:axis”).String)
#set($indentclass = $axis.toLowerCase())
#set ($image = “”)
#set ($hasImage = false )
#foreach($im in $navon.getNodes(“nav:image”))
#set($image = $im)
#set($hasImage = true )
#end
#if($hasImage)
#set ($activeimage = “#imageurl($image ‘active’)”)
#end

#if ( $landing_page )
## don’t process this nav if there is no Landing page
<li><a href="$landing_page"><img src="$activeimage" border=“0” width=“96” height=“36” /></a>
#if ( $submenu )
<ul>
#foreach ($navon in $submenu)
#secondlevel ($navon)
#end
</ul>

#end
	  &lt;/li&gt;

#end
#end

#macro(secondlevel $node)

#set($title = $node.getProperty(“rx:displaytitle”).String)
#set($landing_page = $node.getProperty(“nav:url”).String)
#set($submenu = $node.getNodes(“nav:submenu”))
#set($axis = $node.getProperty(“nav:axis”).String)
#set($indentclass = $axis.toLowerCase())

this template processes the second level navons. Notice we are only processing two levels of navons.

#if ( $landing_page )
<li>
<a href="$landing_page">$title</a>
</li>
#end

#end

#rootlevel($nav.root)

</ul>

Hi Shane

I tend to do this instead:

#set($children = $node.getNodes("nav:submenu"))
#if($tools.math.toInteger($children.size) > 0)
	#foreach($child in $children)

	#end
#end

Cheers
James

Excellent that seems to have done the trick. Thank you.