This guide will help you create a simple "Hello World" module for PrestaShop.
Create Module Directory:
modules
directory.customhelloworld
.Create Main PHP File:
customhelloworld.php
.Edit the customhelloworld.php
file to define your module. Add the following code:
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class CustomHelloWorld extends Module
{
public function __construct()
{
$this->name = 'customhelloworld';
$this->tab = 'others';
$this->version = '1.0.0';
$this->author = 'Your Name';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Custom Hello World');
$this->description = $this->l('A simple Hello World module.');
}
public function install()
{
return parent::install();
}
public function uninstall()
{
return parent::uninstall();
}
public function hookDisplayHome($params)
{
return $this->display(__FILE__, 'views/templates/hook/displayhome.tpl');
}
}
?>
Create Template Directory:
views/templates/hook
.
Create Template File:displayhome.tpl
and add the following content:<div class="hello-world">
<h1>Hello, World!</h1>
</div>
To display the "Hello World" message on the homepage, you need to register the hookDisplayHome
in the module class.
Add the following code to the install method in customhelloworld.php
:
public function install()
{
return parent::install() && $this->registerHook('displayHome');
}
Upload the Module:
Log in to your PrestaShop admin panel.