How can I get the breadcrumb array from my template?

I'm able to get the object:


and full breadcrumb path as final HTML


But when I use getData or toJson it returns the object, not the breadcrumb data.



 array(2) { ["type"]=> string(36)
 "Magento\Theme\Block\Html\Breadcrumbs" ["module_name"]=> string(13)
 "Magento_Theme" }




2 Answers 2


I know this is a rather old question, but since I ran into sort of the same issue I thought I'd share my answer:

If you want to call it in a custom template, I suppose you should make a module first and create a custom Block class. Then use dependency injection to get the Helper\Data from the Magento_Catalog-module, as follows:

namespace Name\Module\Block;

use Magento\Catalog\Helper\Data;

class CustomBreadcrumbBlock {

    protected $catalogData;

    public function __construct(
        Data $catalogData
    ) {
        $this->catalogData = $catalogData;

    public function getBreadcrumbPath() {
        return $this->catalogData->getBreadcrumbPath();

Then you should be able to call $block->getBreadcrumbPath() in your custom block template, which will return an array of your breadcrumb path.

  • it will return breadcrumb only on catalog category and product page
    – Dexture
    Commented Mar 4, 2019 at 8:15
  • will this work on custom pages as well? Commented Jan 13, 2021 at 7:00
  • @VishalParkash I'm not sure. It's been a while since I visited this part of M2. It's worth a try, though. I can't think of any reason why it wouldn't work. Commented Jan 13, 2021 at 11:03
  • For me it did not work, I think Magento2 reads only the defined pages for custom magento2 breadcrumb does not work. It returns empty array Commented Jan 13, 2021 at 12:34

You can also just extend the Magento\Catalog\Block\Breadcrumbs class when you make your custom block class. To use the getBreadcrumbsPath() method you write a public method to access the protected object $catalogData to use Data::getBreadcrumbsPath() (i.e. getCatalogDataHandler()).

Then in phtml-file you can do like $block->getCatalogDataHandler()->getBreadcrumbsPath().

The getBreadcrumbsPath() method gives you an assoc array with some category id as key and link and label in value-array so perhaps its a good idea anyway to write a public block-method that gives you exactly what you want. I just needed the id for the top level category.

CODE:$breadcrumbsBlock = $resultPage->getLayout()->getBlock('Magento\Catalog\Block\Breadcrumbs');

  • why didn't you post the code instead of writing this much of content? Commented Jan 13, 2021 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.