How to Create a New Page in Prestashop Admin Panel

How to create a new page in prestashop admin panel?

create controllers/admin/AdminPageController.php with the follwing content:

    class AdminPageController extends AdminController
{
public function initContent()
{
parent::initContent();
$smarty = $this->context->smarty;

$smarty->assign('test', 'test1');

}
}

Delete: /cache/class_index.php

Create: admin\themes\default\template\controllers\page\content.tpl

zzz{$test}zzz

At BackOffice -> Administration -> Menus -> [Add New]:

Name: Page
Class: AdminPage
Parent: Catalog

Click the [Save] button and the menu item should appear at the "Catalog" menu.

Prestashop add new item in Admin Panel Sidebar Menu

All items that are shown in the sidebar menu have to be an AdminController class and added in the tab of PrestaShop.

Then, in your AdminController, you make the redirection:

<?php

class AdminMyModuleRedirectController extends ModuleAdminController
{
public function init()
{
Tools::redirect('https://www.google.com');
}
}

You still can manually modify the template that shows the sidebar menu, but it's not recommended.

Good luck

Prestashop 1.7 create admin module

Module's install() method must return a true/false.

As for template loading from ModuleAdminController

$this->createTemplate($template); 

tries to find template and load the first one it finds in:

  1. /current_theme/modules/yourmodule/views/templates/admin/
  2. /modules/yourmodule/views/templates/admin/

So if you call createTemplate() with a path it's appended to either of the two folders above and it doesn't find your template and that throws out an error.

Move your template into modules/yourmodule/views/templates/admin/ and call create method with only template name.

$this->createTemplate('mymodule.tpl');

Create new template for CMS pages in prestashop

This worked for Prestashop 16.0.14:

Copy /controllers/front/CmsController.php to /override/controllers/front/CmsController.php and find the last method of the class, which is initContent().

The last line is $this->setTemplate(_PS_THEME_DIR_.'cms.tpl');.
Change it to:

if(is_file(_PS_THEME_DIR_.'cms-'.$this->cms->id.'.tpl')){
$this->setTemplate(_PS_THEME_DIR_.'cms-'.$this->cms->id.'.tpl');
}
else{
$this->setTemplate(_PS_THEME_DIR_.'cms.tpl');
}

Then you need to delete the file /cache/class_index.php to force cache recreation.

Then you can create files inside your theme folder like this: cms-2.tpl where 2 is the id from your CMS page (just duplicate cms.tpl and change filename).
Make sure you keep your cms.tpl as a fallback to all other CMS pages.



Related Topics



Leave a reply



Submit