Get Free Audit

Creating FrontController in the Module and Customization of Displaying Page in Prestashop

Jan 26, 2016

4383 Artsem Miklashevich

Creating FrontController in the Module and Customization of Displaying Page in Prestashop

Prestashop offers handy tools to work on the creation of its FrontController in the module and page customization. You can entirely change the page according to your needs and change not only the right or the left column of the theme, but also footer and header.

It’s not that complicated to create a custom FrontController. It’s inherited from ModuleFrontController


and is located in the directory <root>/modules/<mymodule>/controllers/front/. The class ModuleFrontController is inherited from the FrontController class, with rewriting methods setTemplate(), __construct(), getTemplatePath().

Check the article “How To Implement a Controller In a Custom Module“.

Frontend page can be entirely changed as one desires. In order to disable/enable columns and also footer and header, the following FrontController class properties need to be applied:


Front-end page should contain at least one file – layout.tpl which is by default located in /root/modules/moduleName/views/templates/front/layouts/layout.tpl. But there is only one file for displaying the content and it means there isn’t much flexibility. Let’s say, you need to display several pages with different design. To do this task, it’s convenient to use layout.tpl as an entry point to connect with necessary files, for example:


The header.tpl and footer.tpl files are located one level above the layout.tpl (in fact they can be located anywhere, it’s important to correctly define the $my_module_dir variable).

In order to define the $my_module_dir variable in your controller, you can use the following method:

Andrey_Dubina
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey


If you stock the template files of the module in the /root/modules/moduleName/views/templates/front/ directory , then in the mymoduleFrontModuleFrontController  class code you can use the method inherited from the FrontController :: setTemplate() class :

modules prestashop belvg

PrestaShop Modules

Take your online store to the next level with BelVG PrestaShop Modules

Visit the store


Depending on controller’s logic, you can add any template from the /root/modules/moduleName/views/templates/front/ folder to the FrontController::setTemplate() method.
Andrey_Dubina

Partner With Us

Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey

I would like to point out that in the templates of your module the same variables as in in the main templates of Prestashop theme are available. And you can use these variables if necessary.

In general, to create customized module pages, Prestashop offers enough tools that allow making changes in the design for a Frontend page. For inspiration check how world famous brands running on Prestashop.

development_prestashop

PrestaShop Development

Take your online store to the next level with BelVG PrestaShop Development

Visit the page
Andrey Dubina
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

1 comment

  1. hi Artsem,

    What about your method on Prestashop 1.7 ?
    It seems that $this->setTemplate(‘product-list.tpl’); doesn’t work anymore. Only the tpl of the module is loaded, and not like in 1.6 the common header, footer. No css, js are loaded anymore !

    Looking forward to your comment :)

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *