Question

I am using the opencart open source e-commerce website. The main problem I am having is when I try to separate the breadcrumbs into a single file that I include inside each .tpl file. I have tried using the basic PHP include method although this does not work.

In Reply to Jay's answer:

I have created a new breadcrumbs controller that renders the separate breadcrumb template file.

<?php
class ControllerCommonBreadcrumb extends Controller {

    public function index() {


        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/breadcrumbs.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/common/breadcrumbs.tpl';
        } else {
            $this->template = 'default/template/common/breadcrumbs.tpl';
        }

        $this->render();
    }
}
?>

Although this causes the error:

Notice: Undefined variable: breadcrumbs
Was it helpful?

Solution

To do this, you need to first set the breadcrumb template as a child of the controller action using $this->children, then echoing out the breadcrumbs with that. You will also need to set the id of the breadcrumb controller, so that you know what to echo in your template

Personally I would just add the breadcrumbs to the common/header.tpl file instead, it's far easier

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top