Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Injecting CSS into the layout from within a zf2 module

I'm almost done writing a very simple module for zf2. One thing I'd like my module to do is to inject some css to the layout so that the HTML it generates displays in a nicer way.

Is this possible to do from within a module? If so, how?

EDIT: Thank you all for the prompt responses. However I think I probably didn't explain myself very clearly. When I say "inject some css" I mean taking a string of css and having it actually rendered INSIDE the layout. I didn't mean linking to an external css file or having an asset manager publish my files like the answers so far have suggested.

like image 456
Julian Avatar asked Dec 15 '22 17:12

Julian


1 Answers

See Publishing assets from modules in Zend Framework 2 or How to merge Zend Framework 2 module public directories for discussion of the options you have for pushing public assets from a module.

And in addition to pushing your module assets to public, you could put the append into a triggered method like onBootstrap:

public function onBootstrap($e) {
    $sm = $e->getApplication()->getServiceManager();
    $headLink = $sm->get('viewhelpermanager')->get('headLink');
    $headLink->appendStylesheet('/assets/MyModule/css/mystylesheet.css');
}
like image 176
dualmon Avatar answered Dec 20 '22 08:12

dualmon