View Full Version : css not showing up when css saved as file
squidsk
01-02-2013, 12:33 AM
What code do I need to add/modify to get my css template to show up when the setting save css stylesheets as file to true? The css in the template show up when the setting is false.
I'm guessing its a relatively simple change/addition but I'm not spotting it.
EDIT: This is getting css for elements added to the postbit, not for a custom page
I'm not sure how you're adding your CSS template now, but if you use the function vB_Template::fetch_css_path() to build the url, it should work either way. For instance you could use $template_hook['headinclude_css'] like:
$template_hook['headinclude_css'] .= '<link rel="stylesheet" type="text/css" href="' . vB_Template::fetch_css_path() . 'my_css.css?d=' . $style['dateline'] . '" />';
or if you're putting it in a template you could just use {vb:cssfile my_css.css} .
squidsk
01-02-2013, 03:31 AM
I'm not sure how you're adding your CSS template now, but if you use the function vB_Template::fetch_css_path() to build the url, it should work either way. For instance you could use $template_hook['headinclude_css'] like:
$template_hook['headinclude_css'] .= '<link rel="stylesheet" type="text/css" href="' . vB_Template::fetch_css_path() . 'my_css.css?d=' . $style['dateline'] . '" />';
or if you're putting it in a template you could just use {vb:cssfile my_css.css} .
Currently the template is referred to in two plugins:
The first plugin is at the cache_templates with the following code:
if(THIS_SCRIPT=='css')
{
$cache[] = 'my_css.css';
}
The second is at the css_start hook with the following code:
if(in_array('vbulletin.css',$matches[1]))
{
$matches[1][] = 'my_css.css';
}
As a note I've inherited this code so I'm not sure which of these, if either, is responsible for including the css when css is not stored as a file.
As a note I've inherited this code so I'm not sure which of these, if either, is responsible for including the css when css is not stored as a file.
That first plugin just caches your template, and the second one includes your css template when css.php is called (when CSS is not stored as a file). So unless there's more code somewhere else, it doesn't look like anything was done to include it when CSS is stored as a file. What you can do is create a new plugin using hook parse_templates and code like this:
if ($vbulletin->options['storecssasfile'])
{
$template_hook['headinclude_css'] .= '<link rel="stylesheet" type="text/css" href="' . vB_Template::fetch_css_path() . 'my_css.css" />';
}
But there's one issue - this will load my_css.css on every page. If you can list the pages that actually need it, then you could limit it to those pages by also doing a check of THIS_SCRIPT.
There's another way to do it: create a cssrollup xml file and put it in includes/xml. For exaample you could name it cssrollup_myproduct.xml and have contents like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<css product="my_product_id">
<rollup name="main-rollup.css">
<template>mycss.css</template>
</rollup>
</css>
Then rebuild the styles (under Maintenance > General update tools). Then you don't need any extra code or plugins.
Edit: There are other rollups than 'main', so if you're really concerned about efficiency, you could determined which one you need. There is one called 'postbit' so maybe that would work for you.
squidsk
01-03-2013, 01:40 PM
There's another way to do it: create a cssrollup xml file and put it in includes/xml. For exaample you could name it cssrollup_myproduct.xml and have contents like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<css product="my_product_id">
<rollup name="main-rollup.css">
<template>mycss.css</template>
</rollup>
</css>
Then rebuild the styles (under Maintenance > General update tools). Then you don't need any extra code or plugins.
Edit: There are other rollups than 'main', so if you're really concerned about efficiency, you could determined which one you need. There is one called 'postbit' so maybe that would work for you.
Worked like a charm thanks! The only problem is that there aren't roll-ups for all the pages I need them for so I ended up having to put it into main-rollup.css, but its a small amount of css so I'm not too worried.
The only problem is that there aren't roll-ups for all the pages I need them for so I ended up having to put it into main-rollup.css, but its a small amount of css so I'm not too worried.
I agree, I think it's OK. Also, now that I see you're working on your product - I don't think you would need to rebuild the styles manually if the file is uploaded before the product is imported, so you shouldn't need any special instructions or anything.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.