View Full Version : Conditional Plugin for additional.css
Jacob_ITAPros
05-16-2010, 02:55 PM
I'm attempting to create a plugin that will check certain conditions before appending css to additional.css. Here is what I have for a plugin at hook: cache_templates.
if in_array($foruminfo['forumid'] == array(2,7)) {
$sp_css = array
(
".forumbit_post .foruminfo {;",
" width: 57%;",
" min-width: 30%;",
" float: {vb:stylevar left};",
" clear: {vb:stylevar right};",
" min-height: 85px;",
"}"
)
foreach ($sp_css as $value) {
echo $value;
}
vB_Template::preRegister('additional.css',array('s p_css' => $sp_css))
If there is a way that I can have the array in this plugin display each element I think this would work. The goal in this particular experiment would be, if specfic forum ID's are matched, add these lines to additional.css. Obviously what I have here isn't working.
I'm completely new to PHP and vBulletin so be nice. :-)
Lynne
05-16-2010, 03:02 PM
Why not just create a new css template and just perform your condition and then decide to include the css template or not, rather than appending it to another css template.
Jacob_ITAPros
05-16-2010, 03:06 PM
Why not just create a new css template and just perform your condition and then decide to include the css template or not, rather than appending it to another css template.
So in your suggested scenario, the condition would be added at the bottom of the header inlcude, and the css that is in that file would successfully override the css that I'm attempting to reassign values to?
***EDIT***
Actually I'm not sure that header include is the best place. I only need to override specific css elements that are in forum.php and forumdisplay.php. So I don't need this condition checked on every page.
Zachery
05-16-2010, 03:55 PM
Add your code to the bottom of the head include and be done with it as a normal conditional.
Jacob_ITAPros
05-16-2010, 04:04 PM
Add your code to the bottom of the head include and be done with it as a normal conditional.
Since the condition is based on $foruminfo['forumid'], and this condition would be added to header include per your suggestion, when I encounter a page in which this variable is not recognized, won't I get an error? That's why I thought that maybe adding this particular conditional in FORUMHOME and FORUMDISPLAY just under the {vb:raw headinclude_bottom} statement might be appropriate. I'm only desiring to override a few structures in forumbit.css for certain forums and subforums.
I appreciate the help and advice so far!
Zachery
05-16-2010, 04:05 PM
$GLOBALS[forumid]
Jacob_ITAPros
05-16-2010, 04:15 PM
$GLOBALS[forumid]
Syntax check...the css isn't being inlcuded.
<vb:if condition="in_array($GLOBALS[forumid], array(9,11))">
<link rel="stylesheet" type="text/css" href="/clientscript/vbulletin_css/myfolder/mycss.css" />
</vb:if>
I'm sorry for the nickel and diming.
Zachery
05-16-2010, 04:30 PM
That looks fine, give it a shot? :p what do you have to lose?
Jacob_ITAPros
05-16-2010, 04:40 PM
That looks fine, give it a shot? :p what do you have to lose?
No I mean I placed that code in the headinclude_bottom template just above the statement:
{vb:raw template_hook.headinclude_bottom_css}
And the css file is not being included. I used firebug as well and can't find the inclusion of this file when hitting forum and forumdisplay.
:(
Zachery
05-16-2010, 04:51 PM
Just put it in the headinclude template, why are we being so complicated? :p
Jacob_ITAPros
05-16-2010, 04:56 PM
Just put it in the headinclude template, why are we being so complicated? :p
I've tried that as well. I placed:
<vb:if condition="in_array($GLOBALS[forumid], array(9,11))">
<link rel="stylesheet" type="text/css" href="/clientscript/vbulletin_css/sponsor/sponsor.css" />
</vb:if>
At the bottom of the headinclude template and still nothing. :confused:
When removing the conditional, the file is included. So there is something up with the conditional.
Also, when just trying $foruminfo[forumid], it doesn't work. wtf
--------------- Added 1274041318 at 1274041318 ---------------
It appears that regardless of the reference, the forumid variable is not rendered whether using
$foruminfo[forumid]
$GLOBALS[forumid]
or just $forumid
I've tried everything in the headerinclude and headerinclude_bottom templates. I've also tried registering $forumid @ forumdisplay_start
$forum= array('forumid' => $vbulletin->GPC['forumid']);
vB_Template::preRegister('header',array('forum' => $forum));
My next step is to try forumhome and forumdisplay templates. If it works there, then I'll make the assumption that there is no access to this variable in the headers and that there is no definition of this variable with a global scope. Even if that was the case I'm not sure why the plugin above didn't register the variable.
It was asked earlier why this is being made complicated. I'd like to ask the same thing at this point.
Lynne
05-16-2010, 07:46 PM
I just plugged this in and it worked just fine:
if ($GLOBALS['forumid'] == 4)
$template_hook['headinclude_bottom_css'] .= '<link rel="stylesheet" type="text/css" href="'.$vbcsspath.'additional2.css"" />';
And this works just fine in the FORUMDISPLAY template:
<vb:if condition="$forumid == 4">
<style type="text/css">
html {background: pink;}
</style>
</vb:if>
Sounds like Jacob is running into the same issue many people have faced - "Why aren't the standard vB Variables available to all templates?" (or my version - "How on earth do I get $forum[forumid] to be recognised outside of FORUMDISPLAY?")
Jacob_ITAPros
05-16-2010, 08:30 PM
I just plugged this in and it worked just fine:
if ($GLOBALS['forumid'] == 4)
$template_hook['headinclude_bottom_css'] .= '<link rel="stylesheet" type="text/css" href="'.$vbcsspath.'additional2.css"" />';
And this works just fine in the FORUMDISPLAY template:
<vb:if condition="$forumid == 4">
<style type="text/css">
html {background: pink;}
</style>
</vb:if>
Well then I'm losing my mind because apparently I can't get $forumid to be read from anywhere except forumhome_forumbit_level2_post and similar templates.
Even in the FORUMHOME or FORUMDISPLAY templates, I add this:
<vb:if condition="$forumid == 9">
<link rel="stylesheet" type="text/css" href="clientscript/vbulletin_css/sponsor/sponsor.css" />
</vb:if>
And it does not work. If I remove the conditional and just leave the center action, it works. What in the frack. I'm stumped.
--------------- Added 1274045759 at 1274045759 ---------------
Sounds like Jacob is running into the same issue many people have faced - "Why aren't the standard vB Variables available to all templates?" (or my version - "How on earth do I get $forum[forumid] to be recognised outside of FORUMDISPLAY?")
Kall, I can't even get FORUMDISPLAY to read $forumid in a conditional but it appears that it's read as a variable when referenced as: foruminfo.forumid - just fine.
Lynne
05-16-2010, 09:31 PM
It's not going to work on FORUMHOME because there is no single forumid. But, what I wrote definitely works on my 4.0.3 test board in the FORUMDISPLAY template. I have a pink background only in forumid 4. And, the plugin also works for me on my 4.0.3 test board.
Jacob_ITAPros
05-16-2010, 10:11 PM
It's not going to work on FORUMHOME because there is no single forumid. But, what I wrote definitely works on my 4.0.3 test board in the FORUMDISPLAY template. I have a pink background only in forumid 4. And, the plugin also works for me on my 4.0.3 test board.
I understand. However, I've run into another issue that I should have thought thoroughly through before attempting this method altogether. When including the css file, because the css structures are named the same as elsewhere in forumbit.css, when the condition is true the elements in the css file overwrite ALL of the forums css where I'd only want the css changes made to a specific forum.
So I'll be placing the condition in forumhome_forumbit_level2_post, renaming the css structures to something unique in a new css file, and then referencing them in the div where necessary so that they are only used in a specific forum. Fortunately I don't have this very odd forumid issue in the forumhome_forumbit_level2_post template.
So the solution for me is to use the very same conditional statement that I've referenced throughout this post, only use it in forumhome_forumbit_level2_post with a new css structure altogether. In the end, it worked out the best for me anyhow. So your help has been appreciated and has also contributed to my effort and for that I'm grateful. Thanks Lynn, talk to you again.
--------------- Added 1274115311 at 1274115311 ---------------
To bring closure to this thread, my plan worked. :-)
Basically I have a conditional in the forumhome_forumbit_level2_post template that uses one set of custom references in divs for certain forum id's, and all other forums which are not designated in the array uses the default layout and css references. The challenge here was that I needed to get all of the forrum-rollup css properties for the set of divs that were targeted for change, and recreate those css structures with properties that emulated that change but with different names. Those changes were added to additional.css.
My only setback here is that the same conditional, which is pretty big, has be be placed in one other template so if someone clicks on the forum category, the subsequent forums have the same logic built into them. No biggie, but because the theme of this customization is sponsorship it does mean I will be frequenting these templates when changes occur.
Now if I can just add a control panel for this in the ACP that would be hot. But that's a study for another day.
Thanks for the help :-)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.