Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » include css according to section
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.
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
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!
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » include css according to section
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 1
- User Info:
- Total Users:
- 7671
- Newest User:
- kiresidencescondo2
- Members Online:
- 0
- Guests Online:
- 112
- 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