简体   繁体   中英

Opencart: add module/html inside .TPL

Is there a simple way of calling a module (in this case module/html ) inside a div of the TPL, in WordPress we could use shortcodes to do that, is there any way to do something like that in OpenCart without having to create a new layout position using only the module id for example?

Open controller file of your tpl. For example in catalog/controller/common/header.php

Find (should be row 3)

public function index($setting) {

Add after

$this->load->model('extension/module');
$module_id = 5;  // your html module ID
$custom_html = $this->model_extension_module->getModule($module_id);

if ($custom_html && $custom_html['status']) {
  $data['module_html'] = $this->load->controller('extension/module/html', $custom_html);
}else{
  $data['module_html'] = '';
}  

Than in header.tpl add

<?php echo $module_html; ?>

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