0

I am trying to render product_list.tpl file in home.tpl but it's giving me NULL

Controller File:

/controller/product/product_list.php

Code:

class ControllerProductProductList extends Controller {
    public function index() {

        $this->load->model('catalog/category');

        $this->load->model('catalog/product');

        $this->load->model('tool/image');

        $filter_data = array(
                'filter_tag'          => 'featured',
                'limit'               => 9
            );
        $data['results'] = $this->model_catalog_product->getProducts($filter_data);
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/productlist.tpl')) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/common/productlist.tpl', $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/common/productlist.tpl', $data));
        }
    }
}

Template to render

/template/product/productlist.tpl

Code:

<?php var_dump($results); ?>
<h2>Product are here</h2>

Then adding this line in home.php controller

$data['special_mod'] = $this->load->controller('product/product_list');

and printing $special_mod in common/home.tpl file

Muhammad
  • 921
  • 2
  • 11
  • 29

1 Answers1

0

The problem was in /controller/product/product_list.php

the method $this->response->setOutput doesn't just return the value but send the user to the different page while what I wanted was to just output the productlist.tpl as string so for that I had to replace the code

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/productlist.tpl')) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/common/productlist.tpl', $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/common/productlist.tpl', $data));
        }

with

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/productlist.tpl')) {
            return $this->load->view($this->config->get('config_template') . '/template/common/productlist.tpl', $data);
        } else {
            return $this->load->view('default/template/common/productlist.tpl', $data);
        }
Muhammad
  • 921
  • 2
  • 11
  • 29