简体   繁体   中英

OpenCart Make $products Available in home.tpl File

I'm trying to make the latest products available in the home.tpl file. I've modified the catalog/controller/module/latest.php from:

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

to:

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

But $products is shown to be an Undefined variable: products once the page loads. How would I make $products available on home.tpl?

Note: I have the Latest module loaded with the Layout set to Home and the Position set to Content Top.

You shouldn't have to modify anything in terms of templates for this to work.

Content Top is a child process and is rendered via the controller class whenever it's included in the $children array.

Check your $children array in the home controller, it should look like this:

$this->children = array(
    'common/column_left',
    'common/column_right',
    'common/content_top',
    'common/content_bottom',
    'common/footer',
    'common/header'
);

Check your home.tpl and ensure that the variable $content_top exists.

Make sure the Latest module is enabled .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM