ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Dynamically Including Multiple Stylesheets

December 30, 2009 8:05pm

Subscribe [4]
  • #1 / Dec 30, 2009 8:05pm

    Chris Wetterman

    16 posts

    I need a little guidance here in how to best handle loading multiple stylesheets based on the current weblog. My current structure is that I have a header and footer template and then embed those into all my templates/weblogs. The main css file for the site is linked in the header. How would I then add a weblog-specific stylesheet a particular template? Is there a stylesheet add-on manager for such cases? I know this probably has been asked many times but couldn’t find a thread on it.

    Thanks.

  • #2 / Dec 30, 2009 9:30pm

    Herb

    224 posts

    There are a number of possible solutions.  I have a web site that adds additional css that is triggered by the template group name.

    If you need information from a weblog entry, you can use Reeposition to grab the information and pass it as a variable to your heading embed.

  • #3 / Dec 31, 2009 4:36am

    Dale-

    63 posts

    I need a little guidance here in how to best handle loading multiple stylesheets based on the current weblog. My current structure is that I have a header and footer template and then embed those into all my templates/weblogs. The main css file for the site is linked in the header. How would I then add a weblog-specific stylesheet a particular template? Is there a stylesheet add-on manager for such cases? I know this probably has been asked many times but couldn’t find a thread on it.

    Thanks.

    Chris,

    Depending on your specific needs, you can just create a new html header embed template and link to that on the weblog that needs to access that CSS file. In other words, you can create a new CSS file as a template, say “style_2”, and the embed tags on the weblogs needing it would include that reference.

    I use a template group for embeds (for easier management – not required), and in that group there are several “html_header_x…” templates. A couple are for different scripts or metadata, but a couple are for different CSS links. I prefer not to separate too much of the CSS so that a visitor doesn’t experience any slowdown while the additional files are being loaded into cache, but there are times when separation is simply preferred. For example, a blog and several other pages can use the main CSS, while a Gallery section displaying several portfolios can use a different CSS file controlling it.

    Just name your different header templates to be embedded something different, e.g. html_header_main, html_header_gallery, html_gallery_blog, etc. and set the path to them in your embed tag as needed.

    The same applies if the footer elements are different in certain sections. Create a different footer file to embed on the pages that require the different footer (or any other element).

    HTH,

    Dale

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases