murpg
2005-12-28 14:46:44 UTC
I have created a dynamic menu using ColdFusion and XML. I have run into a
little problem. The menu works great except I am trying to use a pipe |
delimiter to sperate the items in the menu. I don't want to use a pipe
delimiter on my last menu item. I have put an IF statement saying not to use a
PIPE delimiter on the last menu item. It puts it there anyway. I am including
my menu builder and the XML file. It is very short code.
Copy and paste code call file (_main_build_mainrev.cfm) have it in the same
directory as the XML file and you will see what I mean.
<!--- get the current folder --->
<cfset current_dir = getDirectoryFromPath(getTemplatePath())>
<!--- read XML file --->
<cffile
action="read"
file="#current_dir#afrtsmenu.xml"
variable="themenu">
<!--- parse the XML into an array --->
<cfset menu = xmlparse(themenu)>
<!--- <cfdump var="#menu#"> --->
<cfoutput>
<ul>
<!--- loop through the array and get top level items --->
<cfloop index="ls" from="1" to="#arraylen(menu.afrtsmenu.XmlChildren)#">
<!--- loop through the array and get 2nd level items --->
<cfloop index="it" from="1"
to="#arraylen(menu.afrtsmenu.list[ls].XmlChildren)#">
<li><a href="#menu.afrtsmenu.list[ls].item[it].link.XmlText#"
class="nav"> #menu.afrtsmenu.list[ls].item[it].display_text.XmlText#</a><cfif
it LT arraylen(menu.afrtsmenu.XmlChildren)> | <cfelse></cfif></li>
<!--- if not last child then add a seperator --->
</cfloop>
</cfloop>
</ul>
</cfoutput>
This is the XML file call it (afrtsmenu.xml)
<?xml version="1.0"?>
<afrtsmenu>
<list>
<item id="1">
<display_text>HOME</display_text>
<link><![CDATA[index.cfm?ParentID=1&ContentParentID=1]]></link>
</item>
</list>
<list>
<item id="2">
<display_text>FAQ</display_text>
<link><![CDATA[index.cfm?ParentID=2&ContentParentID=1]]></link>
</item>
</list>
<list>
<item id="3">
<display_text>DECODER REPAIRS</display_text>
<link><![CDATA[index.cfm?ParentID=3&ContentParentID=1]]></link>
</item>
</list>
<list>
<item id="4">
<display_text>CONTACT US</display_text>
<link><![CDATA[index.cfm?ParentID=4&ContentParentID=1]]></link>
</item>
</list>
<list>
<item id="5">
<display_text>TRUSTED USERS</display_text>
<link><![CDATA[index.cfm?ParentID=5&ContentParentID=1]]></link>
</item>
</list>
<list>
<item id="6">
<display_text>SYSTEM SETUP</display_text>
<link><![CDATA[index.cfm?ParentID=6&ContentParentID=1]]></link>
</item>
</list>
</afrtsmenu>
little problem. The menu works great except I am trying to use a pipe |
delimiter to sperate the items in the menu. I don't want to use a pipe
delimiter on my last menu item. I have put an IF statement saying not to use a
PIPE delimiter on the last menu item. It puts it there anyway. I am including
my menu builder and the XML file. It is very short code.
Copy and paste code call file (_main_build_mainrev.cfm) have it in the same
directory as the XML file and you will see what I mean.
<!--- get the current folder --->
<cfset current_dir = getDirectoryFromPath(getTemplatePath())>
<!--- read XML file --->
<cffile
action="read"
file="#current_dir#afrtsmenu.xml"
variable="themenu">
<!--- parse the XML into an array --->
<cfset menu = xmlparse(themenu)>
<!--- <cfdump var="#menu#"> --->
<cfoutput>
<ul>
<!--- loop through the array and get top level items --->
<cfloop index="ls" from="1" to="#arraylen(menu.afrtsmenu.XmlChildren)#">
<!--- loop through the array and get 2nd level items --->
<cfloop index="it" from="1"
to="#arraylen(menu.afrtsmenu.list[ls].XmlChildren)#">
<li><a href="#menu.afrtsmenu.list[ls].item[it].link.XmlText#"
class="nav"> #menu.afrtsmenu.list[ls].item[it].display_text.XmlText#</a><cfif
it LT arraylen(menu.afrtsmenu.XmlChildren)> | <cfelse></cfif></li>
<!--- if not last child then add a seperator --->
</cfloop>
</cfloop>
</ul>
</cfoutput>
This is the XML file call it (afrtsmenu.xml)
<?xml version="1.0"?>
<afrtsmenu>
<list>
<item id="1">
<display_text>HOME</display_text>
<link><![CDATA[index.cfm?ParentID=1&ContentParentID=1]]></link>
</item>
</list>
<list>
<item id="2">
<display_text>FAQ</display_text>
<link><![CDATA[index.cfm?ParentID=2&ContentParentID=1]]></link>
</item>
</list>
<list>
<item id="3">
<display_text>DECODER REPAIRS</display_text>
<link><![CDATA[index.cfm?ParentID=3&ContentParentID=1]]></link>
</item>
</list>
<list>
<item id="4">
<display_text>CONTACT US</display_text>
<link><![CDATA[index.cfm?ParentID=4&ContentParentID=1]]></link>
</item>
</list>
<list>
<item id="5">
<display_text>TRUSTED USERS</display_text>
<link><![CDATA[index.cfm?ParentID=5&ContentParentID=1]]></link>
</item>
</list>
<list>
<item id="6">
<display_text>SYSTEM SETUP</display_text>
<link><![CDATA[index.cfm?ParentID=6&ContentParentID=1]]></link>
</item>
</list>
</afrtsmenu>