Create custom page in Prestashop 1.5.3

user1567896 picture user1567896 · Jan 15, 2013 · Viewed 19.8k times · Source

I'd like to create a custom page in Prestashop 1.5.3 without using CMS.

Unfortunately I can not find any tutorials that are working with 1.5.3.

So far I have created a test.php file in the shops root directory with following content:

<?php
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');

$smarty->display(_PS_THEME_DIR_.'test.tpl');
?>

I placed the corresponding test.tpl in my themes basefolder. It simply contains 'hello world'.

I changed the blockmenu.php and created a custom link to my page:

$this->_menu .= '<li><a href="test.php">TEST</a></li>'.PHP_EOL;

If I click the link the page is displayed but the html is some kind of corrupt. The body-id of the page is set to pagenotfound and the left column is generated but is not shown. Is there any way to set the $page_name for my custom page so that I can check if my custom page is loaded and to supress the generation of the left and right columns?

Is there any other way to create a functional custom page without CMS?

Answer

romainberger picture romainberger · Jan 15, 2013

Just create a controller with the name you want for the page, and put it in /overrides/controllers/front/. The name of the controller must be NameyouwantforthepageController.php

Here is a basic class that will work:

class MyPageController extends FrontController {

/**
 *  Initialize controller
 *  @see FrontController::init()
 */
public function init() {
    parent::init();
}

/**
 *  Assign template vars related to page content
 *  @see FrontController::initContent()
 */
public function initContent() {
    parent::initContent();

    $this->setTemplate(_PS_THEME_DIR_.'my-page.tpl');
}

}

Take a look at the FrontController to see what method you need to override to add functionnalities, for example setMedia() to add CSS / JS files.

You will then be able to add a pretty url in the back office in the SEO panel.