Templates 打开将控制器连接到模板的购物车

Templates 打开将控制器连接到模板的购物车,templates,opencart,Templates,Opencart,我在catalouge文件夹中创建了header_top.tpl(在主题“common”文件夹中),然后在controller文件夹中创建了一个控制器。但我不知道如何使用控制器呈现模板(并将数据从控制器发送到模板以供模板进一步解析) 我知道$this->render()确实渲染了模板,但之前对模板发生的情况对我来说是模糊的。在控制器文件中应该有一个类似于下面代码的条件。替换为该部分中的模板文件,如下所示: if (file_exists(DIR_TEMPLATE . $this->con

我在catalouge文件夹中创建了header_top.tpl(在主题“common”文件夹中),然后在controller文件夹中创建了一个控制器。但我不知道如何使用控制器呈现模板(并将数据从控制器发送到模板以供模板进一步解析)


我知道
$this->render()
确实渲染了模板,但之前对模板发生的情况对我来说是模糊的。

在控制器文件中应该有一个类似于下面代码的条件。替换为该部分中的模板文件,如下所示:

 if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header_top.tpl')) {
      $this->template = $this->config->get('config_template') . '/template/common/header_top.tpl';
 } else {
      $this->template = 'default/template/common/header_top.tpl';
 }
设置为
$this->data['sitename']='stackoverflow'的值可用于模板文件,如
echo$sitename


祝你今天愉快

那么数据是如何传递到模板的呢?例如,我想获取用户的名称并将其传递给模板。例如:
$name=get_current_user_name()$数据[“名称”]=$name