API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Breadcrum...

Enter a descriptive title (above) relating to class Breadcrumb, then describe the problem you have found:

I try to render breadcrumb in page.html.twig.

in my custom_theme.theme file i have:

use \Drupal\Core\Breadcrumb\Breadcrumb;

function custom_theme_preprocess_page(&$variables) {
  $variables['breadcrumb'] = Breadcrumb::toRenderable();
}

and I have a php Error:
“Fatal error: Using $this when not in object context in /home/sebcolor/testd8/core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php on line 30”

Comments

sebcolor created an issue. See original summary.

dawehner’s picture

This API certainly doesn't work like that. You need to create a new instance of the Breadcrumb class. Once there you can call toRenderable.

I recommend you to use the block, otherwise have a look what the block is doing to get the breadcrumb out: \Drupal\system\Plugin\Block\SystemBreadcrumbBlock::build

cilefen’s picture

Category: Bug report » Support request
sebcolor’s picture

Thanks for your response. i’ll try by this way.

apaderno’s picture

Issue tags: -breadcrumb, -drupal core +breadcrumbs
Berdir’s picture

Status: Active » Fixed
apaderno’s picture

Issue tags: -PHP

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.