Best way to include module-specific css

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
turniphead
Forum Members
Forum Members
Posts: 40
Joined: Thu Jul 31, 2008 12:16 pm

Best way to include module-specific css

Post 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.
turniphead
Forum Members
Forum Members
Posts: 40
Joined: Thu Jul 31, 2008 12:16 pm

Re: Best way to include module-specific css

Post by turniphead »

Anyone?
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm
Location: Comox Valley, BC

Re: Best way to include module-specific css

Post 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
Last edited by Nullig on Tue May 12, 2009 2:57 pm, edited 1 time in total.
turniphead
Forum Members
Forum Members
Posts: 40
Joined: Thu Jul 31, 2008 12:16 pm

Re: Best way to include module-specific css

Post by turniphead »

Many thanks - that may just be the nudge in the right direction that I needed.
viebig

Re: Best way to include module-specific css

Post 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
turniphead
Forum Members
Forum Members
Posts: 40
Joined: Thu Jul 31, 2008 12:16 pm

Re: Best way to include module-specific css

Post 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.
Post Reply

Return to “Developers Discussion”