How to create a new page using module front controller

So you want to create a new page. It’s really easy, you just need to write a few lines of code.

This tutorial is for PrestaShop 1.6. Other versions are similar but can slightly differ.

Let’s say we want to create a “Test” controller for a module “MyModule“. Change “Test” and “MyModule” to your actual values.

  1. First you need to navigate to your module’s directory.
  2. Create there a new directory “controllers“. And inside it create a directory “front“.
    So the file structure should be “mymodule/controllers/front/”
  3. In that “front” directory create a new PHP file: test.php
  4. Paste the following code into that file:
    1
    2
    3
    class MyModuleTestModuleFrontController extends ModuleFrontController
    {
    }

    As you can see, controller’s class extends ModuleFrontController and should be called like <module_name><controller_name>ModuleFrontController.

All done!

You can view your new page by the following url:
your_site/index.php?fc=module&module=mymodule&controller=test
OR
your_site/module/mymodule/test
Go to your Back Office to the tab Preferences > SEO & URLs. There you can click “Add a new page” and set a custom friendly url for your page.

Now, you can customize the new page

For example, use the display_column_left variable to control left column displaying.

1
2
3
4
class MyModuleTestModuleFrontController extends ModuleFrontController
{
    public $display_column_left = false;
}

Let’s add some content to the new page

Create a new template file: “mymodule/views/templates/front/test.tpl” and place there some text.
Use that template:

1
2
3
4
5
6
7
8
9
class MyModuleTestModuleFrontController extends ModuleFrontController
{
    public function initContent()
    {
        parent::initContent();

        $this->setTemplate('test.tpl');
    }
}

5 thoughts on “How to create a new page using module front controller”

  1. Presta 1.6.1

    Hello,
    first of all, thanks for the explanation.
    I have followed the instructions, but there is a 404 error when I try to open the page …. /index.php?fc=module&module=mymodule&controller=test

    cache/class_index.php was deleted

    Seo & url >> modul-path: module/{module}{/:controller}

    Regards

    Tom

  2. I’m using presta 1.7.6 and the same 404 error.
    Does anyone know to to solve it?

    Cheers
    Victor

Leave a Reply to Victor Cancel reply

Your email address will not be published. Required fields are marked *