Go Back   SitePoint Forums > Forum Index > Program Your Site > ColdFusion
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 3, 2009, 14:28   #1
cydewaze
SitePoint Evangelist
 
cydewaze's Avatar
 
Join Date: Jan 2006
Location: Maryland, USA
Posts: 579
Building an automated menu

I'm currently working on a site design for my office, and I've been trying to think of a way that I can use the same menu file (as an include) on every page, but show different menus for different pages.

Right now my structure looks something like this (example):
  • home
    • fruit
      • pear
      • banana
      • apple
      • orange
    • vegetable
      • brocoli
      • chard
      • tomato
      • pepper
    • meat
      • chicken
      • pork
      • lamb
      • beef

If I drop a menu into the "meat" directory, for example, I want it to show only the subdirectories under "meat". Right now I'm using a bunch of <cfif> statements, but I'm wondering if there's another way, like using <cfdirectory> to get a list of directories in the current directory.

I was also thinking about using <cfswitch>, but that's sort of like using <cfif>.

Any ideas would be appreciated.
cydewaze is offline   Reply With Quote
Old Nov 16, 2009, 12:07   #2
matt1dmb
SitePoint Enthusiast
 
Join Date: Feb 2005
Posts: 44
CFDirectory is decent for this, but if you want to have any sort of "pretty" printing of the directory names it starts to get unwieldy. For example, spaces in directory names can have weird effects depending on servers, etc. I tried doing the same thing recently and spaces caused it to error and not display. Of course, then you can replace spaces with underscores and then modify the output to replace them with spaces, but then what do you do if you truly need an underscore? Etc., etc.

If you wanted to you could add a chunk of code to the Application.cfm or cfc that, given the current location, looks at the subfolders and stores them to a variable for use later in the page.

Something like this:

Code:
<cfdirectory 
directory="#GetDirectoryFromPath(GetTemplatePath())#/" 
name="dirs"
type="file"
sort="name ASC, size DESC">
            
            <ul>
            <cfoutput query="dirs"><li>#dirs.name#</li></cfoutput>
            </ul>
matt1dmb is offline   Reply With Quote
Old Nov 16, 2009, 14:50   #3
downtroden
SitePoint Guru
 
downtroden's Avatar
 
Join Date: Dec 2004
Location: illinois
Posts: 745
I would build the menu in a database (id, title, parent_id) and build your menu that way. Then in the admin section, you can have it create and remove directories when you create or remove a category.
downtroden is offline   Reply With Quote
Old Nov 16, 2009, 20:14   #4
cydewaze
SitePoint Evangelist
 
cydewaze's Avatar
 
Join Date: Jan 2006
Location: Maryland, USA
Posts: 579
Ah, good options, thanks.

I might explore that CFDirectory option more closely. We already have a pretty good directory structure in place (no spaces!) so it shouldn't be too hard to get them to look the way we want.

As for the db option, since we're stuck using Access, I don't want to rely on db hits too much due to performance issues with Access.
cydewaze is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 20:06.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved