Hi guys,
I was wondering if there’s a better way to handle this basic problem.
My site uses three templates, t1, t2 and t3. All three templates use the main ’style.css’ file. Templates t2 and t3 are a little different from the main template, and reference their own css files (’t1.css’ and ’t2.css’) to override certain parts of the main style.css.
Right now I’m using a separate header chunk for each template to keep the css in order, with the appropriate css information for each template in its respective chunk.
I just have the feeling I’m taking the caveman approach (unfortunately my default setting) to this and would really like to hear how this is handled by more experienced folks.
Thanks!
Cris
You could use a snippet like this:
Name:
css
<?php
$templateid = $modx->documentObject['template'];
if ($templateid=="1") {
print 't1.css';
} elseif ($templateid=="2") {
print 't2.css';
} elseif ($templateid=="3") {
print 't3.css';
}
// or load default
else {
print 't1.css';
}
?>
Then in your ONE header chunk:
<link href="assets/templates/css-folder/[[css]]" rel="stylesheet" type="text/css" />
Mr. Haw thanks!
I’ve configured my site with this and it works great. The only problem I have now is that I need to configure this so that two css files are printed out, one after the other.
In the case of template 2, for example, I have to be able to print ’css1’ and then ’css2’ right after it. I’ve tried to figure out how to do this on my own but I can’t. How do I do this in php?
Whether you respond to this request, you already got me 99% of the way to where I need to be with this and I really appreciate the help!
Cris
<?php
$templateid = $modx->documentObject['template'];
$option1 = <<<END
<link href="assets/templates/css-folder/t1.css" rel="stylesheet" type="text/css" />
<link href="assets/templates/css-folder/t2.css" rel="stylesheet" type="text/css" />
END;
$option2 = <<<END
<link href="assets/templates/css-folder/t1.css" rel="stylesheet" type="text/css" />
<link href="assets/templates/css-folder/t3.css" rel="stylesheet" type="text/css" />
END;
if ($templateid=="2") {
print $option1;
} elseif ($templateid=="3") {
print $option2;
}
// or load default
else {
print '<link href="assets/templates/css-folder/t1.css" rel="stylesheet" type="text/css" />';
}
?>
Then instead of your header chunk, have the code inside the $options vars:
$option = <<<END
...
END;
And just call the snippet in the templates.