Prestashop custom page with own template

空扰寡人 提交于 2019-12-08 06:43:21

For PS 1.7, create a new page following the next steps:

Create the controller: /controllers/front/MyPageController.php

<?php

class MyPageControllerCore extends FrontController
{
    public $php_self = 'mypage';
    public $ssl = true;

    public function initContent()
    {
        parent::initContent();

        $this->setTemplate('mypage');
    }
}

Create the tpl file in your theme: /themes/YOUR_THEME/templates/mypage.tpl

{extends file='page.tpl'}

{block name='page_header_container'}{/block}

{block name='page_content'}
  PAGE CONTENT HERE
{/block}

Delete the class index files: /var/cache/dev/class_index.php and /var/cache/prod/class_index.php

How to access it: http://your-site.com/index.php?controller=mypage

Finally:
If you want to handle a friendly URL for this page, just add the page in Shop Parameters > Traffic & SEO.

I think the best practice would be to create a module with your custom page. Because with your approach you may get troubles after prestashop update and also a behavior of your store may be unpredictable with different properties.

Here is some information about how to create own page within a module https://belvg.com/blog/creating-frontcontroller-in-the-module-and-customization-of-displaying-page-in-prestashop.html and https://belvg.com/blog/how-to-implement-a-controller.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!