问题描述:

I want to display existing module in two different places with two different views.

Of course i can create another module, but this doesn't look right, because logic is the same.

On the other side i want to be able to reuse both views, but it looks like i can reuse only modules with hard-wired templates, am I right? Or how can i do it?

网友答案:

At the top of your module's controller, you'll have something like this:

<?php  
class ControllerModuleMyModule extends Controller {
    protected function index($setting) {

If it just says index() then change it to index($setting)

$setting['position'] will contain the name of the position for the current instance, e.g. "content_bottom". So you can just change template based on this.

A basic example:

switch($setting['position']) {
    case 'content_top':
        $template_name = 'my_module_top.tpl';
        break;
    case 'column_left':
        $template_name = 'my_module_left.tpl';
        break;
    default:
        $template_name = 'my_module.tpl';
        break;
}

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/' . $template_name)) {
    $this->template = $this->config->get('config_template') . '/template/module' . $template_name;
} else {
    $this->template = 'default/template/module/' . $template_name;
}
相关阅读:
Top