Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #2
dawehnerThis 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
Comment #3
cilefen CreditAttribution: cilefen commentedComment #4
sebcolor CreditAttribution: sebcolor commentedThanks for your response. i’ll try by this way.
Comment #5
apadernoComment #6
BerdirComment #7
apaderno