We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27500
    • 14 Posts
    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?
      • 9763
      • 16 Posts
      i love this snippet! smiley

      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! smiley

      // 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;
          }
        }
      


        • 13577
        • 302 Posts
        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.
          Standard Disclaimer
          I could be totally wrong.
          • 36747
          • 138 Posts
          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 [tt]$pathThruUnPub = 0[/tt] or [tt]$pathThruUnPub = false[/tt], the snippet dont show the unpublished documents.

          Cheers!
          emi

            patagonia, argentina
          • 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.
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 36747
              • 138 Posts
              My english is a shame. But if $pathThruUnPub works as you said, the detail info about how it works is not right.

              // $pathThruUnPub [ 1 | 0 ]
              // When you path includes an unpublished folder, setting this to
              // 1 will show all documents in path EXCEPT the unpublished.

              What I understand is that if 1 will show all documents in path EXCEPT the unpublished, 0 obvioulsy will show all documents in path including the unpublished.

              I`m right? Or my english is worse that what i think?

              cheers
                patagonia, argentina
                • 13577
                • 302 Posts
                Here’s the down low:

                Unpublished docs are NEVER SHOWN.

                pathThruUnpub = true
                All PUBLISHED documents from current to root page are shown.

                pathThruUnpub = false
                All PUBLISHED documents from current up to root OR first UNpublished document are shown.



                // $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;
                From the documentation example structure (UNpublished docs in all caps):
                home > news > CURRENT > SPORTS > skiiing > article

                Note how the two example paths from the documentation differ:
                $pathThruUnpub = true: home > news > skiiing > article
                $pathThruUnpub = false: home > skiiing > article

                In the (false) example, "news" is missing. The snippet starts from the current document, in this case "article" and moves up the tree including published documents (skiing) until it hits an unpublished document (SPORTS) at which time it stops. If the home crumb is turned on, then home is added as well, as shown in the example.

                Does that help?
                  Standard Disclaimer
                  I could be totally wrong.
                  • 22302
                  • 42 Posts
                  Quote from: skiphreak at Mar 15, 2006, 04:25 AM

                  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 have the same problem, did someone found a workaround?
                    [b]Benoit Deziel[b]
                    • 36541
                    • 222 Posts
                    I made a small modification to the snippet. It didn’t work correctly when called from within a chunk with parameters. Instead of applying overridden values it was falling back to those set in the snippet code. It also didn’t accept ’longtite’ and ’introtext’ for crumb title and description.

                    Changes:

                    • redefinition of variable statements - now overrides from the call should work fine
                    • ’longtitle’ and ’introtext’ added to the pool of available title and description fields
                    • added $homeCrumbDescription - a custom home link description in case you’d need it

                    My modification is based on Breadcrumbs ver. 0.9c dated 2006.03.29. I’m not a coder, so I can’t guarantee it will work for everyone. I just thouhgt of sharing it as it does work for me.
                      This is the web: the only thing you know about who will come is that you don't know who will come.
                      • 7963
                      • 67 Posts
                      Thanks a lot for that Path Snippet, very usefull wink