Oh Crumbs: Using link lists to create nested breadcrumbs

Here's a little nugget that uses link lists to create nested breadcrumbs. Why, you ask? It's one way to give the impression of categories-within-categories that's a little less tricky than using query strings and unlike using tags, it can be used on page objects.

1) Create a snippet for your crumbs. We'll be passing some parameters with the {%include%} tag when referencing it, so let's tackle that before getting into the snippet itself. The first parameter defines the link list you want to use for this set of crumbs, the second defines the current object, we'll be using a page object for this demo. You could play around with assigning these values dynamically, but for now we're going to keep it simple.

2) Onto the snippet. The name of the game is to locate the current object (which could be nested a few levels down) and then define its "parents". For this example we're going to have a maximum of 3 levels, but you could add as many as you need or find a way to work with a dynamic number, we'll update this post if the latter is figured out. For ease of reading we have used "//" for comments rather than a {%comment%} tag, remember to remove those if you are using this.

3) Boom. We now have a variable that contains a string of the parent / child data, we convert that to an array and loop through it to create the crumbs.

And there it is. Please feel free to use / share and leave us a comment if you have any questions or improvements. Cheers!