2016-08-30 210 views
1

我剛開始學習OpenCart,目前使用的是2.3.0.2版本。Opencart模板不渲染

我創建了一個模塊,在後端一切正常。

但是在前端,當我從控制器返回模板時,它顯示空白。

但是,如果我在模板中添加die();,它將加載模板。

控制器代碼:

<?php 
class ControllerExtensionModuleHelloworld extends Controller { 
    public function index() { 
     $this->load->language('extension/module/helloworld'); 

     $data['heading_title'] = $this->language->get('heading_title'); 

     $data['helloworld_value'] = html_entity_decode($this->config->get('helloworld_text_field')); 


     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/extension/module/helloworld.tpl')) { 
      // print_r(__LINE__); 
      return $this->load->view($this->config->get('config_template') . '/template/extension/module/helloworld.tpl', $data); 
     } else { 
      // print_r(__LINE__); 
      return $this->load->view('extension/module/helloworld.tpl'); 
     } 
    } 
} 

模板代碼:

<div class="panel panel-default"> 
    <div class="panel-heading"> <?php echo $heading_title; ?> </div> 
    <div class="panel-content" style="text-align: center;"> <?php echo $helloworld_value; ?> </div> 
    <div style="height:100px;width:100px;background-color:blue;"></div> 
    </div> 

回答

1

通過改變固定它:

return $this->load->view('extension/module/helloworld.tpl', $data); 

到:

$this->response->setOutput($this->load->view('extension/module/helloworld.tpl', $data));