breadcrumb customisation

breadcrumb customisation

by Ian Usher -
Number of replies: 13

Morning!

Further down the page a question's been asked about breadcrumbs, but the discussion wandered into something else and the breadcrumbs thing was never answered (AFAIK).

Anyway, I want to customise what goes in the breadcrumbs as IMHO the -> 'caret' is not that elegant, I'd like to replace it with » or something similar.

In my header.php file I have the snippet

<?php print_navigation("$navigation");

which inserts the breadcrumbs, where is this formatted, i.e. where can I replace "->" with what I want?

Any help appreciated!

Ian.

Average of ratings: -
In reply to Ian Usher

Re: breadcrumb customisation

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
You can use the str_replace function on that $navigation string.

The new Moodle templates will make it easier when they arrive.
Average of ratings: Useful (1)
In reply to Martin Dougiamas

Re: breadcrumb customisation

by Ian Usher -

Thanks Martin, I presume I'd put:

$navigation = str_replace('->', '&raquo;', $navigation);

but wonder where it would go - in weblib.php? My PHP skills aren't all they might be (now there's an understatement) so I don't want to break anything.

I did try replacing (in weblib.php): 

     echo "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">$site->shortname</a> -> $navigation";

with

     echo "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">$site->shortname</a> &raquo; $navigation";

 but that left the final -> still there just before the Current Page title (the rightmost 'breadcrumb' without a link.

VLE » Administration -> Configuration

Thank you for your patience... mixed

In reply to Ian Usher

Re: breadcrumb customisation

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Yep, put that str_replace line immediately before the other one you changed.

You could also put it just before the call to print_navigation in your theme/header.html ... this will reduce the changes needed to the main Moodle code.

I'm trying it here on this site ... looks quite nice!  smile
Average of ratings: Useful (1)
In reply to Martin Dougiamas

Re: breadcrumb customisation

by Nicolas Martignoni -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Yes, very nice and smart.

Do we have a chance to have it in the standard themes in Moodle 1.4? wink
In reply to Martin Dougiamas

Re: breadcrumb customisation

by David Le Blanc -

One thing I always thought was missing in the Moodle breadcrumb navigation was the category of the current course. In other words, if I have a course called français listed in the Modern Languages category, it would be nice to see this reflected in the breadcrumb navigation when inside the course. Currently what shows is:

Site Name -> français

 I think it would be helpful to reflect the entire navigation path such as:

 Site Name -> Modern Languages -> français

In reply to David Le Blanc

Re: breadcrumb customisation

by Chardelle Busch -
Picture of Core developers

The misaligned arrow has always bothered me also (isn't it funny what we spend our time doing when we should be doing other things).

So, please, for we the clueless, could you be more specific how to make this change?

As Martin wrote:

You could also put it just before the call to print_navigation in your theme/header.html ... this will reduce the changes needed to the main Moodle code.

1. Exactly how should the code read in the header.html? Trying to go by the above I changed mine to this:

$navigation = str_replace('->', '&raquo;', $navigation);

print_navigation("$navigation");

But that didn't do anything. 

2. Is there another change, in another place, that has to be made?

Thanks

In reply to Chardelle Busch

Re: breadcrumb customisation

by Genner Cerna -

Actually two files should be edited one: weblib.php and the header.html

In the weblib.php replace the -> to &raquo;

See above example...

Then in the header.html add this line $navigation = str_replace('->', '&raquo;', $navigation);

Before the print_navigation("$navigation");

In reply to Chardelle Busch

Re: breadcrumb customisation

by Ian Usher -

Hi Chardelle,

Here's what the relevant section of my weblib.php looks like. The two bits in bold red are where I've added or changed something. I didn't need to change header.html but, as Martin said above, that is an alternative method of doing it.:

function print_navigation ($navigation) {
   global $CFG;
   if ($navigation) {
       if (! $site = get_site()) {
           $site->shortname = get_string("home");;
       }
      echo "<a target=\"{$CFG->framename}\" href=\"$CFG->wwwroot/\">$site->shortname</a> $navigation";
   }
}

Hope that helps!

Ian.

In reply to Ian Usher

Re: breadcrumb customisation

by Chardelle Busch -
Picture of Core developers

Thanks Ian and Genner,

I really appreciate your help, and thanks Ian for bringing up this change--it makes the nav bar look so spiffy.  Actually, I host my site with Martin and he jumped right in and made the changes for me--now that's service! 

I wanted to mention that I did just check my files and it appears that he did not make any changes to my header.html, only changes to the weblib.php file.  smile

In reply to David Le Blanc

Re: breadcrumb customisation

by Ian Usher -

David - amen to that! The breadcrumb navigational device is intended to illustrate one's position within a site's hierarchy, so I'd say it's essential that this information is included as a matter of course.

It does seem that this is the only area in which the breadcrumbs exhibit 'non-standard' behaviour (I guess there may be others but so far they've not jumped out at me...) and if our users are going to be encouraged to rely on this as one of their main methods of site navigation (along with other things) then I'd say it's essential that its behaviour is consistent.

That's my 2 Euros' worth for today.

In reply to Ian Usher

Re: breadcrumb customisation

by Steven Day -
Thanks for the tip Ian. I tried this but got an error message on my site. I was careful changing the weblib.php file but got a parsing error nevertheless. Rechecking would indicate that it was entered correctly. There were also problems with the header.html file. Since it's a non-standard theme, might I need to change it after all?

Best,

Steven
In reply to Steven Day

Re: breadcrumb customisation

by Ian Usher -

Hi Steven,

Not sure about non-standard themes, I've only been mucking around with the ones that come with Moodle 'out of the box'. Sorry!

Ian.