Prestashop:在Admincontroller中显示简单页面(没有ObjectModel)

时间:2017-02-24 08:41:47

标签: module prestashop templating

我想在Prestashop后台创建一个简单的页面。我不需要任何ObjectModel。

我创建了一个新的管理标签。我的问题在于AdminController。

您可以看到以下代码:变量不会传输到模板文件。我不明白该怎么做。

class AdminAzertyController extends AdminController
{

    public function initContent()
    {

        parent::initContent();

        // Le template smarty

        $tpl_path = _PS_MODULE_DIR_ .'paniersdegout/views/templates/admin/view.tpl';
        $tpl = $this->context->smarty->createTemplate($tpl_path, $this->context->smarty);
        $content = $tpl->fetch();      
        $this->context->smarty->assign('content', $content);

        // Le passage de variable
        $this->context->smarty->assign('test', 'test');

    }
}   

1 个答案:

答案 0 :(得分:0)

要在自定义控制器中呈现自定义tpl文件,您可以使用smarty分配内容。

例如,如果必须渲染自定义模块的customtemplate.tpl文件。

 public function initContent() {

        parent::initContent();

       $content = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'custommodule/views/templates/admin/customtemplate.tpl');

        $this->context->smarty->assign(
                array(
                    'content' => $this->content . $content,
                )
        );
}