如何链接模块与多个tpl文件?

问题描述:

有什么方法可以添加任何模块与多个模板(.tpl)文件的链接?如何链接模块与多个tpl文件?

我不确定,但是像这样:OpenCart欢迎控制器文件。

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

但是这个例子不起作用。

+0

你想在welcome.tpl文件中加载new.tpl内容? –

+0

是的,我想在welcome.tpl上用ajax调用new.tpl,但是如何?例如welcome.tpl。 @AmitMaurya – user5493831

+0

你正在使用哪个版本的opencart? –

对于new.tpl,你必须创建一个名为模块

这里是这样的:

  1. 创建目录/控制器/自定义/ new.php

    <?php 
    class ControllerCustomNew extends Controller { 
    
    public function index() { 
    
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/custom/new.tpl')) { 
         $this->template = $this->config->get('config_template') . '/template/common/new.tpl'; 
         } else { 
         $this->template = 'default/template/common/new.tpl'; 
         } 
    
         $this->response->setOutput($this->render()); 
        } 
    } 
    ?> 
    
  2. 在目录/ view/theme/default/template/custom/new.tpl下创建一个new.tpl文件

    <p>This is new module content</p> 
    
  3. 下创建目录创建一个自定义欢迎控制器/控制器/自定义/的welcome.php

    <?php 
        class ControllerCustomWelcome extends Controller { 
    
        public function index() { 
    
         if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/custom/welcome.tpl')) { 
         $this->template = $this->config->get('config_template') . '/template/custom/welcome.tpl'; 
         } else { 
         $this->template = 'default/template/custom/welcome.tpl'; 
         } 
    
        $this->children = array(
         'common/column_left', 
         'common/column_right', 
         'common/content_top', 
         'common/content_bottom', 
         'common/footer', 
         'common/header', 
         'custom/new' 
        ); 
    
        $this->response->setOutput($this->render()); 
        } 
        } 
    ?> 
    
  4. 下创建目录/视图/主题/默认/模板/自定义/欢迎一个welcome.tpl文件.tpl

    <?php echo $header;?> 
    <p>This is Welcome module content</p> 
    <?php echo $new; ?> <!-- new module content --> 
    <?php echo $footer; ?> 
    
  5. 装入欢迎模块中的前端即http://yourdomain.com/index.php?route=custom/welcome

+0

感谢您的帮助,但不是这个。我想用相同的模块连接两个tpl。 – user5493831

+0

如果你想通过ajax使用,url应该是 'http://yourdomain.com/index.php?route = custom/new' –

+0

谢谢你现在工作.. – user5493831