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:
- /current_theme/modules/yourmodule/views/templates/admin/
- /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
PHP Dynamic Db Page Rewrite Url
Add X Days to Date, Excluding Weekends
Un-Encrypting/Re-Encrypting a Coldfusion Encrypted String in PHP
Php:Difference Between '&&' and 'And'
Namevaluepair Error "Namevaluepair Cannot Be Resolved to a Type"
How to Run from PHP a Bash Script Under Root User
Sharing PHP Session ($_Session) Across Multiple Domain
Extension PHP5 Does Not Parse in Xampp
When Should I Use Closecursor() for Pdo Statements
How to Password Protect Streaming Videos with PHP
How to Replace Some Characters with Asterisks
In Flutter Web Getting 'Xmlhttprequest' Error While Making Http Call
Differencebetween .= and += in PHP
How to Get List of Supported Encodings by Iconv Library in PHP
How to Find the Largest Common Substring Between Two Strings in PHP