Jump to content

Custom Module - Cannot add CSS from front controller


clement_bobbies

Recommended Posts

Hello,

 

I'm currently working on prestashop 1.7.1

 

I've developed a custom module (named stockists) that displays its own template.

 

My controller extends "ModuleFrontController" and is located at : stockists/controllers/front/stockists.php

My template is located at : stockists/views/templates/front/stockists.tpl

 

I'm correctly able to display content, add smarty variables etc..

 

Problem is I can't find the way to add custom css.

The css I want to use is located at : stockists/vews/css/stockists.css

 

In my front controller, I use setMedia function as explain here : http://developers.prestashop.com/themes/assets/index.html

public function setMedia()
{
	$this->registerStylesheet
        (
       	    'module-stockists-style',
       	    'modules/stockists/views/css/stockists.css',
       	    [
	        'position' => 'head',
                'priority' => 150,
	    ]
        );
}

I go deeper in PrestaShop process trying to figure out what's going on but I still don't understand why it dosen't worked well.

 

Is someone having similar issues ?

 

Don't hesitate to ask me for any further information.

Thanks for the help

Link to comment
Share on other sites

  • 2 weeks later...

This is a snippet from our module:

 

 

class AdminPTMBlogPostsController extends ModuleAdminController
{
    public $identifier = 'id_post';
 
    public function __construct()
    {
       ......
    }
 
    public function setMedia()
    {
        parent::setMedia();
        $this->addCSS($this->module->path .'css/powerfulblog_bk.css');
    }
 
 
 
Let me know if that helped.
Link to comment
Share on other sites

Thanks for your reply but this doesn't work for me.

 

If I'm not mistaken, your code is usefull to add CSS to BO (I see you extend ModuleAdminController).

 

My issue is a little bit different because I want to add CSS to FO.

 

I finally reached my goal by adding :

{extends file='page.tpl'}

To my target template.

 

 

But adding this part causes friendly URL issues.

 

My road is as follow :

public function hookModuleRoutes(){


      return array(
          'module-mymodule-mycontroller' => array(
              'controller' => 'bobbiesstockists',
              'rule'     =>  'retailers{/:id}{/:param1}{/:param2}',
              'keywords' => array(
                  'id'     =>   array('regexp' => '[\d]+', 'param' => 'id'),                                                   
                  'param1'    =>   array('regexp' => '[\w-]*', 'param' => 'param1'),                                       
                  'param2'       =>   array('regexp' => '[\w-]*', 'param' => 'param2'), 
               ),
               'params' => array(
                   'fc' => 'module',
                   'module' => 'mymodule',
                   'controller' => 'mycontroller'
               )
           )
        );
        
    }

If I extend my template, I have to send every parameters to diplay template.

 

for instance, this means I can't reach page if "id" or "param1" or "param2" didn't have value.

 

It seems to be tricky to handle friendly URL with custom template module.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...