Page 1 of 1

Best way to include module-specific css

Posted: Wed May 06, 2009 9:23 am
by turniphead
I've done a few searches on this and haven't come up with much.

I have a module which relies on a lot of specific CSS code. I'm currently adding the css to my default template, but would like to have some way of adding the css as part of the module installation so that when I polish it I can make it available to all and they won't need to hack their templates. I'm sure I've missed the obvious solution - any pointers greatly appreciated.

Re: Best way to include module-specific css

Posted: Tue May 12, 2009 12:45 pm
by turniphead
Anyone?

Re: Best way to include module-specific css

Posted: Tue May 12, 2009 2:54 pm
by Nullig
Have a look at the Album module - it has it's own stylesheet.

Alternately, you could look at the code for adding a stylesheet (lib/classes/class.stylesheetoperations.inc.php I believe) and include it in your install, along with a post install message alerting the user to attach it to their template.

Nullig

Re: Best way to include module-specific css

Posted: Tue May 12, 2009 5:54 pm
by turniphead
Many thanks - that may just be the nudge in the right direction that I needed.

Re: Best way to include module-specific css

Posted: Tue May 12, 2009 7:06 pm
by viebig
The best way is the proper way:

The proper way is include the stylesheet in the

What I would do is assign a variable inside a module template, turn process_whole_template false in cinfig, and if the variable exists include the stylesheet in the head section of the template.

This can avoid some problems. For example if you load a page and immediatelly click on a image on the album page and the stylesheet is not loaded(this count for scripts too), the CSS/Script, will not work if they're not cached.

Regards

G

Re: Best way to include module-specific css

Posted: Wed May 13, 2009 7:46 am
by turniphead
Thanks Viebig,

If I am understanding you correctly, your solution requires that the template is aware of the plugin. I'm looking for a solution that will work on anybody's template.