Breadcrumb template block

Permalink
Hi, I am trying to insert into my template a breadcrumb template block but I am not able to get the right breadcrumb.

The structure of the website is like:

home
-- level 1
-- section
--- article


The code I am using is:

<?php
$autonav = BlockType::getByHandle('autonav');
$autonav->controller->orderBy = 'display_asc';
$autonav->controller->displayPages = 'top'; 
$autonav->controller->displaySubPages = 'relevant_breadcrumb'; 
$autonav->render('templates/breadcrumb');
?>


I added it into my custom theme `elements/header.php`

But in in the article page I only got:

Home > level 1


instead of:

Home > level 1 > section > article


I was not able to find the error.
Thanks for your help,
Giuseppe

carusog
 
CC3381 replied on at Permalink Reply
CC3381
benfrainuk replied on at Permalink Reply
benfrainuk
Well, pay attention to Jordan's info before mine (he's a C5 Ninja) but here is the code I used which works like you want it:

<?php $breadcrumbs = BlockType::getByHandle('autonav');
                           $breadcrumbs->controller->displayPages = 'first_level';
                           $breadcrumbs->controller->orderBy = 'display_asc';                    
                           $breadcrumbs->controller->displaySubPages = 'relevant_breadcrumb';  
                           $breadcrumbs->controller->displaySubPageLevels = 'all';
                           $breadcrumbs->render('templates/breadcrumb'); 
                      ?>
carusog replied on at Permalink Best Answer Reply
carusog
Ok, first of all, thank you both.
The reference article (btw, great C5 resource!) was great and very clear about options.

@benfrainuk
The code snippet made me notice I forgot to add the `breadcrumbs->controller->displaySubPageLevels` variable. Once added, it worked perfectly.

You should change your `displayPages` variable from

$breadcrumbs->controller->displayPages = 'first_level';


to

$breadcrumbs->controller->displayPages = 'top';


since `first_level` is not a valid variable.

It works anyway since default is `top`. Try to remove it and it works as well.
I prefer to keep it ("explicit is better then implicit").

The full working code is:

<?php
    $breadcrumbs = BlockType::getByHandle('autonav');
    $breadcrumb->controller->orderBy = 'display_asc';
    $breadcrumb->controller->displayPages = 'top'; 
    $breadcrumb->controller->displaySubPages = 'relevant_breadcrumb'; 
    $breadcrumb->controller->displaySubPageLevels = 'all';
    $breadcrumb->render('templates/breadcrumb');
?>
carusog replied on at Permalink Reply
carusog
Do you know how to exclude pages with "exclude_nav" attribute checked?
I am now able to get rid of them. :(
webporter replied on at Permalink Reply
webporter
Months late, I know... but I just wanted to add that I put the breadcrumb trail into my template by creating Global Stack called "Breadcrumb" that simply contains my autonav block with the breadcrumbs custom template applied.

All I add to my template is this code:

<?php
$bc = new GlobalArea('Breadcrumbs');
$bc->display();
?>

Everything else is created/configured within the c5 user interface.

This puts breadcrumbs on all pages of my site.

Works well for me :)