Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
No se puede cargar el archivo js y css en Front Controller de Prestashop

Creé una nueva página en mi módulo creando un nuevo controlador frontal. Quiero agregar archivos js y css a esta página, pero no puedo hacerlo. He probado un par de cosas, pero ninguna me funciona.

Intenté agregar la función setMedia() en el controlador frontal:

 public function setMedia() { parent::setMedia(); $this->registerJavascript( 'module-easypaymentoption-front', 'modules/' . $this->module->name . '/views/js/front.js', [ 'priority' => 200, 'attribute' => 'async', ] ); }

También intenté cargarlo usando el enlace actionFrontControllerSetMedia en el archivo php del módulo principal:

 public function hookActionFrontControllerSetMedia() { Media ::addJsDef([ 'easypaymentoption' => $this->context->link->getModuleLink($this->name, 'validation', [], true), ]); $this->context->controller->registerJavascript('modules-easypaymentoption', 'modules/' . $this->name . '/views/js/front.js'); $this->context->controller->registerStylesheet( 'module-easypaymentoption-style', 'modules/' . $this->name . '/views/css/front.css' ); }

También traté de agregar usando hookHeader en el archivo php del módulo principal:

 public function hookHeader() { $this->context->controller->addCSS($this->_path . '/views/css/front.css'); }

Ninguno de los que probé está funcionando, ¿alguien puede ayudarme, por favor?

Cualquier ayuda es muy apreciada.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar los ganchos en los archivos principales del módulo y no en los frontControllers.

Prueba esto en tu archivo controllers/front/yourcontrollername.php:

 public function setMedia() { parent::setMedia(); $this->context->controller->registerJavascript( 'mymodulename', 'modules/'.$this->module->name.'/views/js/mymodulejs.js', array( 'position' => 'bottom', 'priority' => 150 ) ); }

Y no olvide borrar el caché o intente restablecer su módulo si no funciona, porque esta es la forma oficial de agregar JS y CSS a los controladores frontales de PrestaShop.

about 4 years ago · Juan Pablo Isaza Report

0

He respondido a esto en el foro de PrestaShop donde también se publicó, publicación del foro

Intente agregarlos en hookDisplayHeader O, si su versión es> 1.7.6.0, puede intentar:

 $this->context->controller->registerStylesheet(sha1($css_path), $cssUrl, ['media' => 'all', 'priority' => xx]); $this->context->controller->registerJavascript(sha1($js_path), $jsUrl, ['position' => 'bottom', 'priority' => xx]);

donde css_path, js_path y xx son sus variables. También en hookDisplayHeader.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!