Mark Smith (marksmith) wrote in lj_dev,
Mark Smith
marksmith
lj_dev

Creating and Using Breadcrumbs

Figured I'd write up a short guide to dealing with crumbs, as that's what I've spent the majority of the past few days dealing with.

First off, crumbs are organized in a tree. The base of the tree is 'home', which is the front page. Every crumb has a unique key for itself and one (only one) parent. Each crumb is also defined as having a default English title and a link to its page.

In the relevent crumbs definition files (cgi-bin/crumbs.pl and crumbs-local.pl) you will find the hashes that define the crumbs. If you want to add a new crumb, you need to add it to one of these files. Note that crumbs in crumbs-local.pl will override crumbs in crumbs.pl. Files from ljcom NEED to have their crumbs put into crumbs-local.pl.

The hashes are organized as so:

     'unique_key' => [ 'Title of Crumb', '/some/page.bml', 'my_parent' ]

That's a static crumb. Once you've defined one of those in the relevant Perl file, you can then tell LiveJournal to display that crumb on a BML page by using this code:

     LJ::set_active_crumb('unique_key');

Run that anywhere inside of a BML page's code block. If you have a page that doesn't have a code block, you should insert one in the following manner:

<?_code
     return LJ::set_active_crumb('unique_key');
_code?>


There is also the capability to insert dynamic crumbs. If you wish to have a crumb title reflect something like "Support Request #1784835" then you will need to use a dynamic crumb. You can use it something like this:

     LJ::set_dynamic_crumb(BML::ml('.foo', { 'num' => 5 }), 'parent');

Notice that we call BML::ml. This means that the crumb title can be pulled from the translation database, and you can still stick in the data that you want.

I think that's about it. Let me know if there are any questions, or if any of this is unclear. Thanks!

Update: I forgot to mention. When you edit the crumbs files, you need to put them into the translation database. This is, as you probably expected, done with bin/upgrading/texttool.pl. In specific, there is a new "loadcrumbs" option as well as a "wipecrumbs" option.

The easiest way is to do:

    bin/upgrading/texttool.pl load

If you use loadcrumbs instead of load, make sure to also use the makeusable mode so that the crumbs really show up on the site.
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 4 comments