|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() 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):
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. |
|
|
|
|
|
#2 |
|
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>
|
|
|
|
|
|
#3 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() 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.
|
|
|
|
|
|
#4 |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() 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. |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 20:06.









Linear Mode
