Reading list Switch to dark mode

    Adding Breadcrumb in PrestaShop 1.7 Module Front Controller

    Updated 7 December 2016

    Add Breadcrumb in PrestaShop 1.7 Module Front Controller By a function :

    PrestaShop 1.7 has been released early and there are many changes from code end like Symfony introduced and the default theme is updated to a new classic theme.

    If you are developing Module for PrestaShop 1.7. This version introduced a new way of managing the Breadcrumbs on every page. In V1.6, we were managing breadcrumbs on tpl page but now we can manage this by a php function.

    You are just needed to add this PHP function in your module front controller, You can see then the breadcrumbs in your front page.

     

    Searching for an experienced
    Prestashop Company ?
    Read More
    public function getBreadcrumbLinks()
    {
        $breadcrumb = parent::getBreadcrumbLinks();
    
        $breadcrumb['links'][] = [
            'title' => $this->getTranslator()->trans('Women', [], 'Breadcrumb'),
            'url' => $this->context->link->getModuleLink('module_name', 'controller_name')
         ];
    
        $breadcrumb['links'][] = [
            'title' => $this->getTranslator()->trans('T-shirts', [], 'Breadcrumb'),
            'url' => ''
         ];
    
         return $breadcrumb;
     }

    Initial Prestashop versions is not translating the string written in trans() function for non-native modules. You can use

    $this->module->l(‘Women’, ‘controller_name’)

    instead of this.

    Finally, Breadcrumb will look like this,

    Breadcrumb in Prestashop V1.7

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    5 comments

  • Deleval Denis
    Hi Dheeraj,
    Thanks for your help !
    Denis
  • Deleval Denis
    Hi Dheeraj,

    I was looking for changing the breadcrumb in my module. I followed your tip but it didn’t work on PS 1.7.2.0:
    I pasted your code into
    class MyModuleManageModuleFrontController extends ModuleFrontController
    {

    #yourcode

    }
    But on Front end I cannot see the default breadcrumb. Perhaps I missed something …

    However I’ve tried out with success this method:
    class MyModuleManageModuleFrontController extends ModuleFrontController
    {
    public function initContent()
    {
    parent::initContent();
    $this->assign();
    }

    /**
    * Assign manage list template
    */
    public function assign()
    {

    $links[] = array(
    ‘title’ => ‘ex1’,
    ‘url’ => $link->getPageLink(‘my-account’, true)
    );
    $links[] = array(
    ‘title’ => ‘ex2’,
    ‘url’ => ‘another url’
    );
    $links[] = array(
    ‘title’ => ‘ex3’,
    ‘url’ => ”
    );

    $context->smarty->assign(‘breadcrumb’, array(‘count’ => count($links), ‘links’ => $links));
    }
    }

    • Dheeraj Sharma
      getBreadcrumbLinks() this is not my function, this prestashop default function. I have overrided this and add my own breadcrumb.

      Do not use your own assign() function just override getBreadcrumbLinks() function and write your code in this function.

      Correct code;
      public function getBreadcrumbLinks()
      {
      $breadcrumb = parent::getBreadcrumbLinks();

      $breadcrumb[‘links’][] = [
      ‘title’ => $this->getTranslator()->trans(‘ex1’, [], ‘Breadcrumb’),
      ‘url’ => $this->context->link->getPageLink(‘my-account’, true)
      ];

      $breadcrumb[‘links’][] = [
      ‘title’ => $this->getTranslator()->trans(‘ex2’, [], ‘Breadcrumb’),
      ‘url’ => ‘another url’
      ];

      $breadcrumb[‘links’][] = [
      ‘title’ => $this->getTranslator()->trans(‘ex3’, [], ‘Breadcrumb’),
      ‘url’ => ”
      ];

      return $breadcrumb;
      }

      Remove $this->assign(); from initContent();

  • Zyfraglover
    Thank’s for the tip! very usefull and way better than TPL’s imo :)à
    • Dheeraj Sharma
      Thanks @zyfraglover:disqus
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home