Adding CSS styles to our module
We decided to use the actionFrontControllerSetMedia
hook execution to manage the insertion of our CSS style sheet into all the website pages. As $params
is an empty array, in that case, there is no way to act on any variable.
The solution is to use $this->context
, the instantiation of the Context
singleton. It contains the controller
variable, an instance of the current controller
object, and a child class of FrontController
. Then, we can use registerStylesheet($id, $relativePath, $params = [])
, available in all instances of FrontController
. Let’s see how to do it for real:
public function hookActionFrontControllerSetMedia($params) { $this->context->controller->registerStylesheet( 'whreinsurance-style', $this->_path.'views/css/whreinsurance.css', ...