Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Question about the breadcrumbs public function

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 3322 Views
  • SilverRay
    Avatar
    Community Member
    167 Posts

    Question about the breadcrumbs public function Link to this post

    Using $Breadcrumbs in a template will generate a trail of links with the page title as link name. I think it would be better to have the navigation label as link name (after all, it is navigation, and in my case some pages have rather long page titles). If I understand it correctly, the breadcrumbs get generated by a public function in SiteTree.php:

       public function Breadcrumbs($maxDepth = 20, $unlinked = false,
                                                 $stopAtPageType = false) {
          $page = $this;
          $parts = array();
          $i = 0;
          while(($page && (sizeof($parts) < $maxDepth))   ||
                   ($stopAtPageType && $page->ClassName != $stopAtPageType)) {
             if($page->ShowInMenus || ($page->ID == $this->ID)) {
                if($page->URLSegment == 'home') {
                   $hasHome = true;
                }
                $parts[] = (($page->ID == $this->ID) || $unlinked)
                   ? Convert::raw2xml($page->Title)
                   : ("<a href=\"" . $page->Link() . "\">" . Convert::raw2xml($page->Title) . "</a>");
             }
             $page = $page->Parent;
          }

          return implode(" &raquo; ", array_reverse($parts));
       }

    So, if I replace 'Title' with 'MenuTitle' it would do what I want, right? Can I safely do this, or are there other functions in the CMS that depend on the fact that the breadcrumb function uses 'Title'?

    Thanks in advance!

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: Question about the breadcrumbs public function Link to this post

    Hmm. Anyone?

  • KatB
    Avatar
    Community Member
    94 Posts

    Re: Question about the breadcrumbs public function Link to this post

    My answer is to test and see, and if it goes *kaboom*, try to undo what you did, and if that doesn't help, just re-install

  • SilverRay
    Avatar
    Community Member
    167 Posts

    Re: Question about the breadcrumbs public function Link to this post

    Well, yeah, you're right of course, and this is certainly doable on a test server, no problem. But even if things seem to be OK, there can always be that little catch and those things are sometimes easily answered by one of the core devs, so I just tried to get a little response ;)

    More so actually, because I really wondered why one would want page titles in a breadcrumb trail and not navigation labels...

  • KelaniNichole
    Avatar
    Community Member
    2 Posts

    Re: Question about the breadcrumbs public function Link to this post

    SilverRay, I'm in 100% agreement with you on this one. The page titles make no sense in the breadcrumbs, after all bread crumbs are NAVIGATION items. Did you ever find a solid solution to this? I'm pretty new to SilverStripe, not really into modifying core files yet, but I for sure want the navigation label instead of the page titles in my breadcrumbs.

  • KelaniNichole
    Avatar
    Community Member
    2 Posts

    Re: Question about the breadcrumbs public function Link to this post

    Modifying the SiteTree.php file as you outlined above seems to have done the trick. I'm a little hesitant to publish modified core code, but its certainly working beautifully on my development site.

    Thanks for starting this thread, and posting that solution!

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: Question about the breadcrumbs public function Link to this post

    I would agree that having the menu title is a better option. I've never understood why it was setup the way it was.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Question about the breadcrumbs public function Link to this post

    Make this a ticket + patch and one of the core devs can merge this in. Fully agree with the Nav label thing, as long as it defaults to page title if nav label doesn't exist for some reason.

    I would think you can do this pretty safely, doubt it will break too much which relies on that. Maybe you would even want to pass a parameter to the Breadcrumbs function with what field name to use - defaulting to MenuTitle. So then you could if so some reason you had a custom field you could display that instead / Title if you want

    3322 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.