Is it possible to integrate javascript in a module without a direct injection in the template smarty?
Solved ,
I added a Js file in my module directory (ex : mymodule/views/js/abo_front.js).
In my module class, I created a Hook to the header to declare my js file in the header.
public function install()
{
return parent :: install() && $this->resetDb()
&& $this->registerHook('header');
}
public function hookHeader($params)
{
$this->context->controller->addJS(($this->_path).'views/js/abo_front.js');
}
Related
While trying to render a custom HTML tag <my-element> in JSX an error displayed
Property does not exist on type 'JSX.IntrinsicElements'
I've found some examples of how to do that using
declare global {
interface IntrinsicElements {
"my-element": any
}
}
but this produced another error:
ES2015 module syntax is preferred over custom TypeScript modules and namespaces #typescript-eslint/no-namespace
I've found the useful link to Typescript guide which helped me a lot:
The main idea is to create a new file with extension d.ts (e.g. myModule.d.ts) which should contain the following
export as namespace JSX;
export interface IntrinsicElements {
"my-element": any;
}
I would like to edit and add features to the prestashop Store Locator page.
Prestashop's documentation isn't really clear, and i would like to know if it's possible to implement a Controller in a custom module.
I would like to create a module which is able to extends StoreFrontController and it's features without starting from scratch.
Is it possible ? Have you some documentation for me ?
A beginner,
Best.
As you have many requirements, you will have to go with an override of class StoresController.php.
Your module folder should look like this:
/mymodule
/mymodule.php
/config.xml
/override
/controllers
/front
StoresController.php
/views
/templates
/front
stores.tpl
In StoresController.php you will have to override initContent():
<?php
class StoresController extends StoresControllerCore
{
/**
* Assign template vars related to page content
* #see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();
// here add any smarty variables you want
$this->setTemplate(_PS_MODULE_DIR_.'mymodule/views/templates/front/stores.tpl');
}
}
Now you can add as many variables as you want in this controller and customized its template in your own module.
We you create an override in a module, it will be only parsed once at installation. If your module is already installed you will have to uninstall it and install it again. Then your override file will be copied to the root /override folder.
Any change made in your module override will not be reflected to the root override folder. So you will have to uninstall and install your module each time you want to make a change.
So I advise you to make all your changes directly in the root override folder, and when you're done copy this file back into your module folder. And if you don't want to uninstall your module and install it again to declare this file, you can put it directly in the root override folder and delete the file /cache/class_index.php so that Prestashop knows that an overrides has been added.
If you have any questions :)
You can start by overriding front controller like
`"/modules/mymodule/override/controllers/front/StoresController.php" and in this fine add class "class StoresControllerCore extends FrontController {
public function initContent()
{
parent::initContent();
//here do whatever you like
}
}"
though you must know coding to proceed further.
Working on a project that consist to create thumbs for the product's features,
is there a way to override the core controller *AdminFeaturesController*using a module?
In your module you can create a /override directory. Under this directory you will create this file /override/controllers/admin/AdminFeaturesController.php.
This file should look as follow:
<?php
class AdminFeaturesController extends AdminFeaturesControllerCore
{
// Only override the functions that should be modified
public function function_that_i_want_to_override() {
}
}
The override will be effective after module installation.
I want to build a module where , we like to build the form and table using smarty.
In prestashop module controller load template file like
/modules/my_module/views/templates/front/my_module.tpl
where admin will be /modules/my_module/views/templates/admin/admin_module.tpl
My point is how can i show this admin_module.tpl in the prestashop module configuration page.
It is really easy. You just have to create views/templates/admin/foo.tpl and then only display your template in getContent() method:
public function getContent()
{
return $this->display(__FILE__, 'views/templates/admin/foo.tpl');
}
How can I call a module in another module? This code works on my Controllers in Protected/Controllers:
$image = Yii::app()->image->save($photofile, 'some_name','uploadedGal');
But in the controller of my other module (admin) I get this error.
Property "CWebApplication.image" is not defined.
I have defined the image module in my main config file:
'modules'=>array(
'image'=>array(
'createOnDemand'=>true, // requires apache mod_rewrite enabled
'install'=>true, // allows you to run the installer
),
'admin',
),
You need to include the other module components in your module class. Something like this:
class AdminModule extends CWebModule
{
public function init()
{
$this->setImport(array(
'admin.models.*',
'admin.components.*',
'image.models.*',
'image.components.*',
));
}
You can import the module components in the config/main.php like below:
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.admin.models.*',
'application.modules.admin.components.*',
....
....
),
This way all models etc will be imported for you.