jaredc
Coding Team

Posts: 290
|
 |
« on: Feb 24, 2006, 08:36 AM » |
|
Snippet: Breadcrumbs Version: 0.9c Description: This snippet was designed to show the path through the various levels of site structure back to the root. It is NOT necessarily the path the user took to arrive at a given page. Based on PageTrail snippet by: Bill Wilson.
You can download the code below. I'm also posting the changelog just incase anyone is interested.
|
|
|
« Last Edit: Mar 29, 2006, 06:55 AM by jaredc »
|
Logged
|
Standard Disclaimer I could be totally wrong.
|
|
|
Djamoer
Testers

Posts: 1,492
No one can limit a man other than the man himself.
|
 |
« Reply #1 on: Feb 24, 2006, 08:52 AM » |
|
Nice one Jaredc,
here is a little modification from me, to allow defining parameters on the snippet calling. I also add 2 more snippet parameters for user to define the title and description field to be used. If none specified, it will defaulted to pagetitle.
I haven't tested this yet, so jaredc, feel free to change and modify it accordingly.
Sincerely,
|
|
|
|
Logged
|
|
|
|
jaredc
Coding Team

Posts: 290
|
 |
« Reply #2 on: Feb 24, 2006, 09:17 AM » |
|
Hm... makes the config section a little more cluttered than I am used to, but extends the capability of the snippet. To me, this seems like one of those snippets that you like to have be consistent throughout the site, so individualized instances with different parameters are probably not going to be used very often. Still, it doesn't seem to hurt things so I don't see why not.
As far as allowing the developer to to specify which field to use as the the title and description, I suppose that's okay too. Though setting the default in the config section to "pagetitle" for both the $titleField and $decField doesn't make much sense to me since the title and description will default to "pagetitle" if the desired field doesn't exist regardless. I think I'll change those to menutitle and description respectively. I think this will give the best "out of the box" behavior for most users. Those who want can change it.
Thanks for the input. I'll get a 0.9b out soon. Do any PHP zealots out there know if adding a bunch of isset() variable checks will do much damage on speed? Doesn't seem like it to me, but I thought I'd ask.
|
|
|
|
|
Logged
|
Standard Disclaimer I could be totally wrong.
|
|
|
Djamoer
Testers

Posts: 1,492
No one can limit a man other than the man himself.
|
 |
« Reply #3 on: Feb 24, 2006, 09:22 AM » |
|
There is always is a performanceissue, but a note to add, it might only affect 0.0000000000000000000001 second. Believe me, it won't suffer from performance issue, considering all the speed of computer right now; instead it will give more greater usability. 
|
|
|
|
|
Logged
|
|
|
|
jaredc
Coding Team

Posts: 290
|
 |
« Reply #4 on: Feb 24, 2006, 09:29 AM » |
|
...it won't suffer from performance issue... Yeah. I didn't think so. But I thought I'd ask. If I ask "stupid" questions long enough, eventually I'll run out of them and that will have to mean I'm smart... right?  Anyway, the 0.9b version is now attached at the top of the forum.
|
|
|
|
|
Logged
|
Standard Disclaimer I could be totally wrong.
|
|
|
Djamoer
Testers

Posts: 1,492
No one can limit a man other than the man himself.
|
 |
« Reply #5 on: Feb 24, 2006, 10:27 AM » |
|
Hey jaredc, it's not like a stupid questions ya know, it's more to intellectual questions. Some people might don't care about it at all, and later they realize it's a crucial things. 
|
|
|
|
|
Logged
|
|
|
|
Djamoer
Testers

Posts: 1,492
No one can limit a man other than the man himself.
|
 |
« Reply #6 on: Feb 28, 2006, 09:49 AM » |
|
Added to repository
|
|
|
|
|
Logged
|
|
|
|
bernd
Jr. Member

Posts: 4
I love MODx!
|
 |
« Reply #7 on: Mar 03, 2006, 01:57 PM » |
|
hi there, I had a problem using the breadcrumb snippet. I don't know if it is due to my special configuration, but I wanted to share it with you:
the parameters I defined as false ( as in showCrumbsAtHome=false ) didn_t work, because in the snippet the variable is treated as an boolean, but it actually is a string "false" and thus if ("false") evaluates as true.
After the Line if(!isset($showCrumbsAtHome)) $showCrumbsAtHome = true; I added a line else if($showCrumbsAtHome== "false") $showCrumbsAtHome= false;
for all boolean parameters, and now it works great for me.
|
|
|
|
|
Logged
|
|
|
|
edge
Support Subscriber

Posts: 201
|
 |
« Reply #8 on: Mar 03, 2006, 02:23 PM » |
|
Thanks Jaredc and Wendy Just what I needed, great timing and works perfectly for me 
|
|
|
|
|
Logged
|
|
|
|
Djamoer
Testers

Posts: 1,492
No one can limit a man other than the man himself.
|
 |
« Reply #9 on: Mar 03, 2006, 03:34 PM » |
|
hi there, I had a problem using the breadcrumb snippet. I don't know if it is due to my special configuration, but I wanted to share it with you:
the parameters I defined as false ( as in showCrumbsAtHome=false ) didn_t work, because in the snippet the variable is treated as an boolean, but it actually is a string "false" and thus if ("false") evaluates as true.
After the Line if(!isset($showCrumbsAtHome)) $showCrumbsAtHome = true; I added a line else if($showCrumbsAtHome== "false") $showCrumbsAtHome= false;
for all boolean parameters, and now it works great for me.
Nice catch bernd, it's my bad, it's not jaredc fault. I forgot that every vars is treated as string on snippet calling.
|
|
|
|
|
Logged
|
|
|
|
skiphreak
Jr. Member

Posts: 13
I love MODx!
|
 |
« Reply #10 on: Mar 14, 2006, 10:25 PM » |
|
I have an issue with the generated URLs after 2 levels. I'm using all the Friendly URL settings on the admin page. This may have something to do with it. I had a similar problem with NewsListing that I fixed by adding "<base href="[(site_url)]" />" to the head section of the template.
Here's an example: /dir1/dir2/dir3/dir4
A page that calls Breadcrumbs from dir2 will show the correct URL for dir1. But, a page at dir3 shows link to: dir2 as: /dir1/dir2/dir1/page.html # extra dir1 dir1 as: /dir1/dir2/page.html # extra dir2 home as: /dir1/dir2/page.html # extra dir2
With 4 levels, the problem gets worse, dir4 shows links to: dir 3 as: 12312 # extra /dir1/dir2 appended dir2 as: 1231 # extra dirs: 3,1 dir1 as: 123 # extra dirs: 2,3 home as: 123 # extra dirs: 2,3
I do have MODx installed on my Apache public folder path as /folder/modx and not at the root of /modx. Would that cause this issue? Any ideas how to tweak the code, or if I'm doing something wrong?
|
|
|
|
|
Logged
|
|
|
|
fizzy
Jr. Member

Posts: 16
I love MODx!
|
 |
« Reply #11 on: Mar 29, 2006, 05:50 AM » |
|
i love this snippet!  i have come across a minor issue using it though, so i thought i would post how i got around it here. this has not been tested but seems to work for me. my problem:i was using the default breadcrumb snippet (so the current crumb was not a link) i found that while the previous crumbs showed up as menu titles, the current crumb was showing up as the page title. this was the case whether i used the default settings, or set a titleField parameter. whatever setting i used, the page title showed up on the home page crumb instead of the menu title. i had a look through the snippet code and found this: // show current page, as link or not if ($showCurrentCrumb){ if ($currentAsLink && (!$respectHidemenu || ($respectHidemenu && $docInfo['hidemenu'] != 1 ))){ $titleToShow = ($docInfo[$titleField])? $docInfo[$titleField] : $docInfo['pagetitle'] ; $descriptionToUse = ($docInfo[$descField]) ? $docInfo[$descField] : $docInfo['pagetitle'] ; $ptarr[] = '<a href="[~'.$modx->documentIdentifier.'~]" title="'.$descriptionToUse.'">'.$titleToShow.'</a>'; } else { $ptarr[] = $docInfo['pagetitle']; } }
i could well be completely wrong, but it seemed to me that if you do not want the current crumb to be a link, the current crumb is being set to $docInfo['pagetitle'] in all cases?? workaround:i modified the above branch as below, just to always use the titleToShow variable to determine the current crumb once a current crumb is to be shown (regardless of whether it should be a link or not). i am new to editing snippets, but it seems to work for me now - i am seeing menu titles everywhere!  // show current page, as link or not if ($showCurrentCrumb){ $titleToShow = ($docInfo[$titleField])? $docInfo[$titleField] : $docInfo['pagetitle'] ; if ($currentAsLink && (!$respectHidemenu || ($respectHidemenu && $docInfo['hidemenu'] != 1 ))){ $descriptionToUse = ($docInfo[$descField]) ? $docInfo[$descField] : $docInfo['pagetitle'] ; $ptarr[] = '<a href="[~'.$modx->documentIdentifier.'~]" title="'.$descriptionToUse.'">'.$titleToShow.'</a>'; } else { $ptarr[] = $titleToShow; } }
|
|
|
|
|
Logged
|
|
|
|
jaredc
Coding Team

Posts: 290
|
 |
« Reply #12 on: Mar 29, 2006, 07:01 AM » |
|
VERION UPDATE 0.9c
Thanks fizzy - good catch. I have corrected the code as suggested. I also modified the boolean params to be [ 1 | 0 ] rather than [ true | false ] as PHP will correctly interpret the string (i.e. "0") or integer (0) as false and "1" or 1 as true. This is pretty consistent with the way I generally do my config options that can be called from the snippet call parameters. This just formalizes it. This was an odd case because the snippet changed a version ago to make ALL parameters available thru snippet calls - which is not my typical setup and I hadn't thought that thru.
Generally, I'd discourage altering a snippet to accept only the string "false" becaue if there is ever a typo or something, then things go haywire and it's not always easy to find simple mispellings (i.e. fasle) when scanning code. But to each their own.
|
|
|
|
|
Logged
|
Standard Disclaimer I could be totally wrong.
|
|
|
eemi
Moderators

Posts: 126
|
 |
« Reply #13 on: Apr 13, 2006, 08:36 PM » |
|
excelent snippet! but... i`m having problems with this // $pathThruUnPub [ 1 | 0 ] // When you path includes an unpublished folder, setting this to // 1 will show all documents in path EXCEPT the unpublished. // Example path (unpublished in caps) // home > news > CURRENT > SPORTS > skiiing > article // $pathThruUnPub = true would give you this: // home > news > skiiing > article // $pathThruUnPub = false would give you this: // home > skiiing > article (assuming you have home crumb turned on) if(!isset($pathThruUnPub)) $pathThruUnPub = 1; I think that the text is wrong. It should say // $pathThruUnPub = false would give you this: // home > news > current > sports skiiing > article (assuming you have home crumb turned on) But the big problem is that when setting $pathThruUnPub = 0 or $pathThruUnPub = false, the snippet dont show the unpublished documents. Cheers! emi
|
|
|
|
|
Logged
|
patagonia, argentina
|
|
|
rthrash
Foundation

Posts: 9,575
|
 |
« Reply #14 on: Apr 13, 2006, 11:36 PM » |
|
It shouldn't show unpublished documents. It should allow the snippet to show documents that are published and that are children of unpublished folders though.
|
|
|
|
|
Logged
|
MODx is a framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Community participation and questions are encouraged, especially when you help us help you, read the wiki, and review snippet parameters – even if you have to look at the source. Searching the forums helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.
|
|
|
|