Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[HOW TO - VB4] Adding Stylesheets to Your vB4 Mod via Plugins
CarlitoBrigante's Avatar
CarlitoBrigante
Join Date: Nov 2002
Posts: 182

 

Iceland
Show Printable Version Email this Page Subscription
CarlitoBrigante CarlitoBrigante is offline 11-24-2009, 10:00 PM

THIS ARTICLE IS NO LONGER NEEDED FOR vB 4.0.0+: you can now just use the hook in the headinclude_bottom template: headinclude_bottom_css. As I wrote at the beginning of this tutorial, this was to help people working with beta versions.

As many coders have noticed, we still don't have a template hook in headinclude to add our own CSS to the css.php call in the template. Additionally, the simple method I am listing here might still be useful in the future, even when we get that hook.

One of the great things of the new vBulletin, in fact, is that you can manipulate CSS generation as you have been used to in your scripts.

Here you go.

1. First, add a template in Style & Templates, and assign it to your product in development. Let's call this template yourproduct.css.
2. Now, add a plugin for your product for caching this template. Go to Plugin Manager -> Add Plugin, call the plugin as you prefer, then choose the cache_template hook, and finally put the following code in it:
Code:
if(THIS_SCRIPT=='css')
{
   $cache[] = 'yourproduct.css';
}
3. Add another plugin for your product. Choose the css_start hook, then place this code in it:
Code:
if(in_array('vbulletin.css',$matches[1]))
{
   $matches[1][] = 'yourproduct.css';
}
The in_array check makes sure that your CSS is added only to the main vbulletin.css call.

That's it - your CSS will be added to the generated CSS file.
Reply With Quote
  #2  
Old 01-01-2010, 11:23 AM
Brother Malachi Brother Malachi is offline
 
Join Date: Jun 2008
Posts: 208
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How do you assign a template to a product?
Reply With Quote
  #3  
Old 01-01-2010, 04:07 PM
CarlitoBrigante's Avatar
CarlitoBrigante CarlitoBrigante is offline
 
Join Date: Nov 2002
Location: Iceland
Posts: 182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
$config['Misc']['debug'] = true;
Add this to your config file. If you are using it on a live site, I'd recommend putting a conditional to enable debug only for your IP:

Code:
if($_SERVER['REMOTE_ADDR']=='xxx.xxx.xxx.xxx') $config['Misc']['debug'] = true;
Once done, you will see a product selection box in your vBulletin Style manager when adding a template.
Reply With Quote
  #4  
Old 01-03-2010, 11:09 AM
Shadab's Avatar
Shadab Shadab is offline
 
Join Date: Apr 2007
Location: Bhopal
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
But you could also do a different check, for example in case you only need the CSS for users using google chrome:
vbulletin-chrome.css has nothing to do with Google Chrome.
vBulletin "chrome" refers to the main Header, Navigation and Footer elements.
Reply With Quote
  #5  
Old 01-03-2010, 03:55 PM
CarlitoBrigante's Avatar
CarlitoBrigante CarlitoBrigante is offline
 
Join Date: Nov 2002
Location: Iceland
Posts: 182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hehe right, changing this. Completely forgot about this tutorial, I wrote it a few days after the beta release to us.
Reply With Quote
  #6  
Old 01-13-2010, 02:01 PM
NgocTam NgocTam is offline
 
Join Date: Apr 2008
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not work with 4.0.1 if choose "Store CSS Stylesheets as Files"

I need other solution. Merge our custom template with additional.css (?). How can I do it?
Reply With Quote
  #7  
Old 01-13-2010, 06:04 PM
CarlitoBrigante's Avatar
CarlitoBrigante CarlitoBrigante is offline
 
Join Date: Nov 2002
Location: Iceland
Posts: 182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello,

yes, this article is now obsolete. You can now just use the headinclude_bottom_css hook to add your stylesheets. It would probably be even better if there was a hook into additional.css as well. As I wrote above, this was mostly for people working with the beta at the time of this writing.

If you still want to use this method, you can add a conditional to add the call for the static files in the template hook above only in case static CSS is enabled. But this would be really useless, I think.
Reply With Quote
  #8  
Old 01-14-2010, 01:41 AM
NgocTam NgocTam is offline
 
Join Date: Apr 2008
Posts: 104
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

includes\adminfunctions_template.php:

function: write_style_css_directory($styleid, $parentlist, $dir = 'ltr')

Query (in line 769):
PHP Code:
$set $vbulletin->db->query_read($sql "
        SELECT DISTINCT title
        FROM " 
TABLE_PREFIX "template
        WHERE styleid IN (" 
$parentlist ") AND title LIKE '%.css'
    "
); 
My css template like *.css. But in CSS file I don't see it. Is It a bug?
Reply With Quote
  #9  
Old 01-14-2010, 02:03 AM
CarlitoBrigante's Avatar
CarlitoBrigante CarlitoBrigante is offline
 
Join Date: Nov 2002
Location: Iceland
Posts: 182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, if you read the file further, you will see that the result of the query is used only to generate the css file into the directory. After that, you still have to add the path to the headinclude, as I said above. That is why I said the method in the article is still valid, but you need also to add the link to the CSS file... which makes the whole purpose of this article meaningless

A way of having your custom CSS added to the generated files would be to assign it a template type of "css"; but I think you can do this via XML file only (or query), and I am not sure of consequences as I have not explored the possibility.

In brief, easier to use a simple template hook, even though I can understand that some want to have products self contained in an XML file. This would be possible if the developers added a template hook into additional.css.
Reply With Quote
  #10  
Old 01-15-2010, 01:08 PM
MARCO1's Avatar
MARCO1 MARCO1 is offline
 
Join Date: Jun 2008
Posts: 872
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by CarlitoBrigante View Post
No, if you read the file further, you will see that the result of the query is used only to generate the css file into the directory. After that, you still have to add the path to the headinclude, as I said above. That is why I said the method in the article is still valid, but you need also to add the link to the CSS file... which makes the whole purpose of this article meaningless

A way of having your custom CSS added to the generated files would be to assign it a template type of "css"; but I think you can do this via XML file only (or query), and I am not sure of consequences as I have not explored the possibility.

In brief, easier to use a simple template hook, even though I can understand that some want to have products self contained in an XML file. This would be possible if the developers added a template hook into additional.css.
What's about open new project for that in vbulletin.com ? I think it will be very nice to use template hooks also we want our products automatically installation.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:48 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04563 seconds
  • Memory Usage 2,299KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete