Jump to content

add .js file to backend module


Recommended Posts

Hi.

 

I'm trying to add my custom .js file to one backed module.

Any suggestions how to do this correctly?

 

Tried adding:

$this->output .= '<script type="text/javascript" src="../modules/'.$this->name.'custom.js"></script>';

in main .php module file between:

public function getContent() {
}

and it's not working.

Link to comment
Share on other sites

  • 2 weeks later...

Hi.

 

I'm trying to add my custom .js file to one backed module.

Any suggestions how to do this correctly?

 

Tried adding:

$this->output .= '<script type="text/javascript" src="../modules/'.$this->name.'custom.js"></script>';

in main .php module file between:

public function getContent() {
}

and it's not working.

 

 

Hello,

 

1. register hook - displayBackOfficeHeader

 

Example:

    public function install()
    {
        return parent::install() &&
            $this->registerHook('header') &&
            $this->registerHook('displayBackOfficeHeader') &&
            $this->registerHook('displayHome');
    }

2. Add js file custom.js

 

Example:

    public function hookDisplayBackOfficeHeader()
    {
        if (Tools::getValue('configure') != $this->name) {
            return;
        }

        $this->context->controller->addJS($this->_path.'views/js/custom.js');
    }
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...