Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

include css according to section

include css according to section

Hi folks, I'm having a problem thats driving me up the wall on a website http://www.bloodsweatandcheers.com/
Basically I have 5 main sections and I want to style each one with its own css template.

Is if possible for me to load the css files in perhaps the debug module position depending on what section the site is in? I have already got the modules to appear like this, but I wasn't sure if the css would render.

It would save me so so much time. Thank you kindly in advance.

lordbarron
Guest
useravatar
Offline
Administrator has disabled public posting

Re: include css according to section

Hmmm, well I am not sure that MetaMod is the right way to achieve this (generally CSS manipulation is done in the template, or via setting a CSS Class Suffix on particular components or modules), but since you asked... it's easy to achieve.

First, create some CSS rules and put them into a string variable:

$css = 'body { font-size:100%; }
a {font-weight:bold;}
div.spacer {margin:1em;}
';

Then, as part of your rule, you can tell Joomla to include this CSS in the header. This places the CSS directly into the page rather than linking to a file. You could do that too, but for a few basic CSS rules it' more efficient to put them straight into the header like this:

$doc = & JFactory::getDocument();
$doc->addStyleDeclaration($css);

So to put all this into a rule, do the following:

Code:

if ( $option == 'com_content' and (int)$id == 50 ) { /*arbitrary rule */

  $css = 'body { font-size:100%; }
   a {font-weight:bold;}
   div.spacer {margin:1em;}
  ';
  $doc = & JFactory::getDocument();
  $doc->addStyleDeclaration($css);
}

Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3314 Posts
User info in posts
Administrator has disabled public posting

Re: include css according to section

Ok well that looks great for adding short snippets of css. What is the posibility however of changing the template based on the active section being viewed? I hope you managed to get a platform to do your php4 regression testing btw.

lordbarron
Guest
useravatar
Offline
Administrator has disabled public posting

Re: include css according to section

Thank You!  Works as a charm! I have a page with three categories and for all articles in each category only the headers have a specific color. I used this code to make it work:

Code:


// color for category #1 (lime)

if ($option == 'com_content'
and $view == 'article'
and JRequest::getVar('catid') == '1' ) {

  $css = '.contentheading, h1, h2, h3  {
  color: #9c0 !important; }';

  $doc = & JFactory::getDocument();
  $doc->addStyleDeclaration($css);

}

Nice way of using MetaMod!

tekfix
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1685
Total Polls:
6
Total Posts:
5912
Total Posts Today:
4
User Info:
 
Total Users:
11504
Newest User:
toko solo
Members Online:
0
Guests Online:
124

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked