Nov 20, 2008, 06:36 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Search via SMF or Google: modx forums all of modxcms.com web
  MODxCMS.com   Forums   Help Login Register  
News:Donate to MODx: Donations
Pages: [1] 2   Go Down
  Print  
Author Topic: DropMenu: Have empty folders link to first child document?  (Read 6970 times)
0 Members and 1 Guest are viewing this topic.
The Man Can!
Testers
*
Posts: 292



WWW
« on: Nov 12, 2005, 10:24 PM »

Hi all.
The site I'm doing right now has a main vertical menu on the left, and a submenu along the top (http://access.themancan.com). I'm using DropMenu for both menus. The first menu item (About) is an empty folder that contains 5 content items.

The DropMenu snippet allows for empty folders (with template=blank) to be displayed as non-links. My question is: How can I make it display empty folders (with template=blank) be links to the first child element?

I've spent a few hours trying to hack the DropMenu snippet but haven't had any luck. Right now I have it set up with a meta refresh TV, which is sloppy and slower, but it does maintain the "current page" indication in both menus. (I've tried making those empty parent folders weblinks to the appropriate child, but weblinks don't do well at all in the DropMenu snippet. I've tried .htaccess redirects also, but those don't work either. I can't think of anything else that would maintain the current page indication.)

Thanks so much for any help!
-Brett
Logged

Need MODx Ecommerce? Try FoxyCart!
Dr. Scotty Delicious
Coding Team
*
Posts: 1,172


Dr. of Fine Pirate Arts


WWW
« Reply #1 on: Nov 12, 2005, 11:36 PM »

Looks like you found a workaround.  Are you using a <META HTTP-EQUIV="Refresh" CONTENT="0; URL=example_page.html">?

-sD-
scotty Delicious
Logged

We pillage, we plunder, we rifle and loot. Drink up me 'earties, Yo Ho!
We kidnap and ravage and don't give a hoot. Drink up me 'earties, Yo Ho!
Yo Ho, Yo Ho! A pirate's life for me.
sottwell
Documentation Team
*
Posts: 8,170



WWW
« Reply #2 on: Nov 13, 2005, 12:18 AM »

(I've tried making those empty parent folders weblinks to the appropriate child, but weblinks don't do well at all in the DropMenu snippet.

Odd, I'm using weblinks extensively with DropMenu in multilanguage sites, where the "parent" folder is the container for all of the language content for that language. One DropMenu makes a single-level "languages" menu out of the root folder, and the other makes the main menu out of the folders within the given "root" language folder, so I use a weblink within the second level to the "root" langauge folder, which doubles as the langauge home page, so that there is a "Home" link as well; they work just fine.  In fact, I even have one template where I have an empty folder full of weblinks for a "links" menu, and use DropMenu for it with no trouble.
Logged

sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html
The Man Can!
Testers
*
Posts: 292



WWW
« Reply #3 on: Nov 13, 2005, 01:34 AM »

Thanks so much Susan and Scotty for the responses.
I am indeed using a meta refresh, and though it works, it's kind of hackish.

Susan, whenever I try to use a weblink it seems to default thinking it's an empty category and will not apply a link to it.  I'm using
Code:
[!DropMenu? &menuName=navMain &topnavClass=navMain &levelLimit=1 &useCategoryFolders=false !]
and it's still looking like this:


Based on the DropMenu instructions (within the snippet) it seems like setting the useCategoryFolders to false should work, but it doesn't seem to do anything with a weblink. It seems like the problem may be that weblinks cannot have a template applied to them, and the DropMenu looks for the template to be "blank".

Susan, if I understand you correctly, you're using weblinks to point back to the parent folder, yes? Are you able to get the current page indication on a weblink? I've tried that technique on the "Resources" link but it doesn't give indication.
=================================================
I figured it out. I changed the line (around 218):
$itsEmpty = ($isFolder && ($child['template'] == '0'));
to
$itsEmpty = ($isFolder && ($child['template'] == '10'));
and it displays a weblink as a link. "You are here" works beautifully as well. (I'm sure the '10' could be anything else other than 0.)

I think the problem is that somehow it's not acknowledging the useCategoryFolders on a weblink. I even hardcoded it in the snippet to false and it still didn't change anything. Any ideas there?

Thanks so much for your patience and help! I really appreciate your expertise and time. -Brett
Logged

Need MODx Ecommerce? Try FoxyCart!
sottwell
Documentation Team
*
Posts: 8,170



WWW
« Reply #4 on: Nov 13, 2005, 01:47 AM »

No, I haven't gotten the "here" to work on it; I haven't really worried about it since the site involved only has one level for each langauge, and the multilanguage part was "interesting" enough.  I have never used that useCategoryFolder argument.  Looks like that part of DropMenu needs a bit of tweaking so it doesn't regard a weblink as an empty document.
Logged

sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html
sottwell
Documentation Team
*
Posts: 8,170



WWW
« Reply #5 on: Nov 13, 2005, 02:00 AM »

...the line (around 218):
$itsEmpty = ($isFolder && ($child['template'] == '0'));

Why can't that condition be ($child['content'] == "")?

Seems to me basing a condition on something specific that the user has to do when creating his documents is kind of iffy, but if needed  I would rather have to specifically put something in the document's description, such as "empty folder", then the condition could check for that.  That way you know for sure it's not going to be getting tangled up in other things, like the template issue with weblinks.

$itsEmpty = ($isFolder && ($child['description'] == 'empty folder'));

(and, with your solution, what happens when you have ten or more templates, and want to use the 11th template?  All of your folders will show as empty!)

« Last Edit: Nov 13, 2005, 02:02 AM by sottwell » Logged

sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html
OpenGeek
MODx Co-Founder
Foundation
*
Posts: 5,007


looking a little more like my avatar again...


WWW
« Reply #6 on: Nov 13, 2005, 11:45 AM »

An alternative approach to this would be to simply use a snippet in the content of the folder document that finds and redirects itself to the first child.  Here is one I wrote for this purpose quite some time ago for Eto, updated for MODx...

Code:
if (!isset($id)) $id=$modx->documentIdentifier;
$children=$modx->getActiveChildren($id,'menuindex','ASC');
if (!$children===false)
{
$firstChild = $children[0];
$firstChildUrl = $modx->makeUrl($firstChild['id'], $firstChild['alias']);
}
else
{
$doc = $modx->getDocument($modx->config['site_start']);
$firstChildUrl = $modx->makeUrl($doc['id'],$doc['alias']);
}
return $modx->sendRedirect($firstChildUrl);
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
  — Frank Herbert
Dr. Scotty Delicious
Coding Team
*
Posts: 1,172


Dr. of Fine Pirate Arts


WWW
« Reply #7 on: Nov 13, 2005, 12:13 PM »

This topic piqued my interest becuase I have three folders on my site (Lyrics, Templates, and Tutorials) that "hold" other documents, but contain no content themselves.  My solution was to just put some cheezy generic description of the folders sub pages as its content, but I really like the idea of being able to have a document immediately loaden on selecting a blank folder.  Jason, your suggestion seems to be pretty sensible and it appears that it doesn't take much to configure.  Thanks for porting and sharing that snippet from eto.

-sD-
scotty Delicious
Logged

We pillage, we plunder, we rifle and loot. Drink up me 'earties, Yo Ho!
We kidnap and ravage and don't give a hoot. Drink up me 'earties, Yo Ho!
Yo Ho, Yo Ho! A pirate's life for me.
OpenGeek
MODx Co-Founder
Foundation
*
Posts: 5,007


looking a little more like my avatar again...


WWW
« Reply #8 on: Nov 13, 2005, 02:14 PM »

No problem...and actually to make it more efficient (by reducing database calls) in the current version of MODx, I'd remove the getDocument.  This was in the code because in Etomite, the makeUrl function required the alias to be specified for a document in order for it to render properly with friendly URL's.  In MODx 0.9.0+, you do not need to specify the alias for the function to return the proper alias, so we can actually reduce this code down to...

Code:
if (!isset($id)) $id=$modx->documentIdentifier;
$children=$modx->getActiveChildren($id,'menuindex','ASC');
if (!$children===false)
{
$firstChild = $children[0];
$firstChildUrl = $modx->makeUrl($firstChild['id']);
}
else
{
$firstChildUrl = $modx->makeUrl($modx->config['site_start']);
}
return $modx->sendRedirect($firstChildUrl);

I just called it FirstChild, and you can supply an optional `id` snippet parameter to specify a different folder from which to retrieve the first child.  You could also easily modify the default set in the else block to be something other than the site_start page.
Logged

Jason Coward
MODx Co-Founder
xPDO Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual.
  — Frank Herbert
Dr. Scotty Delicious
Coding Team
*
Posts: 1,172


Dr. of Fine Pirate Arts


WWW
« Reply #9 on: Nov 13, 2005, 03:26 PM »

Tre cool man!  Thank you so much for sharing!

-sD-
scotty Delicious
Logged

We pillage, we plunder, we rifle and loot. Drink up me 'earties, Yo Ho!
We kidnap and ravage and don't give a hoot. Drink up me 'earties, Yo Ho!
Yo Ho, Yo Ho! A pirate's life for me.
The Man Can!
Testers
*
Posts: 292



WWW
« Reply #10 on: Nov 13, 2005, 11:06 PM »

$itsEmpty = ($isFolder && ($child['description'] == 'empty folder'));
Thanks Susan, that works beautifully. Mine was a quick hack that worked for my immediate needs, but your solution is quite elegant and still maintains the functionality if desired. I tried it with $child['content']=='' but it still doesn't seem to respect the useCategoryFolders, so no go.

Thanks again!
Logged

Need MODx Ecommerce? Try FoxyCart!
The Man Can!
Testers
*
Posts: 292



WWW
« Reply #11 on: Jan 03, 2006, 06:58 AM »

I just got around to using that snippet and it works like a charm.  Thanks a ton for creating it.  Very very handy.

Just gotta put it in the [! !] brackets, not the [[ ]].
Logged

Need MODx Ecommerce? Try FoxyCart!
bobtk
Jr. Member
*
Posts: 16


« Reply #12 on: Jan 22, 2006, 03:54 PM »

Hi All.

I'm also trying to get this "thing" working, but still without success.
I've read this thread again and again and I think reading it again will confuse me more and more!  Huh


Please, can anyone explain the solution for a Dummy like me? Grin

Thanks for any help!
Boris
Logged
The Man Can!
Testers
*
Posts: 292



WWW
« Reply #13 on: Jan 22, 2006, 04:30 PM »

Hi Boris,
The best way to do this is just to have a regular document as the parent, and put Jason's snippet in the content.  That's it!

I've taken to calling Jason's snippet FirstChildRedirect, and have attached a very slightly modified version of the snippet to this post.  This method seems to be better than using links (and hacking the DropMenu snippet) in my experience. (After having done both a few times, it's just easier to use the snippet with regular documents, rather than weblinks.  Documents are more felxible, can have TVs attached so you can set up nice @INHERIT stuff, etc.)

Just make sure you call the snippet uncached, so [!FirstChildRedirect!] rather than [[FirstChildRedirect]].

Best,
Brett

* snpt.FirstChildRedirect.txt (0.4 KB - downloaded 539 times.)
Logged

Need MODx Ecommerce? Try FoxyCart!
bobtk
Jr. Member
*
Posts: 16


« Reply #14 on: Jan 23, 2006, 01:13 PM »

Brett

thank you very much!  Cheesy
Now I got it! It is just a little confuse reading two different solutions at once.

Thanks again!
Boris
Logged
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP

Copyright © 2005-2008 MODxCMS, All rights reserved. Contact Us
Styles by ziworks.com

Powered by SMF 1.1.4 | SMF © 2005, Simple Machines LLC

Valid XHTML 1.0! Valid CSS!