Php 如何将模块与多个tpl文件链接?
是否有任何方法可以添加带有多个模板(Php 如何将模块与多个tpl文件链接?,php,opencart,opencart2.x,opencart-module,Php,Opencart,Opencart2.x,Opencart Module,是否有任何方法可以添加带有多个模板(.tpl)文件的模块链接 我不确定,但像这样:OpenCart欢迎控制器文件 if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/welcome.tpl')){ $this->template = $this->config->get('config_template') . '/template/m
.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';}
但是这个例子不起作用。对于new.tpl,您必须创建一个名为new 方法如下:
<?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());
}
}
?>
<p>This is new module content</p>
这是新的模块内容
<?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());
}
}
?>
<?php echo $header;?>
<p>This is Welcome module content</p>
<?php echo $new; ?> <!-- new module content -->
<?php echo $footer; ?>
这是欢迎模块内容
http://yourdomain.com/index.php?route=custom/welcome
你想在welcome.tpl文件上加载new.tpl内容吗?是的,我想在welcome.tpl上用ajax调用new.tpl,但如何?welcome.tpl就是一个例子@AMITMAURYA您正在使用哪个版本的opencart?opencart 1.5.6.4@AMITMAURYATS感谢您的帮助,但不是这个。我想用同一个模块连接两个tpl。如果你想通过ajax使用,url应该是
http://yourdomain.com/index.php?route=custom/new