PDA

View Full Version : Template Css adding in my addon


Asterix_ita
08-24-2011, 10:51 AM
I used this plugin to upload my template.css, but sometimes is it loaded and others no why? (vBulletin 4.1.5)


<plugin active="1" executionorder="5">
<title>CSS</title>
<hookname>parse_templates</hookname>
<phpcode><![CDATA[
if($vbulletin->options['ct_list_active'])
{
$template_hook['custom_css_list'] .= ',ct_thread.css';
}
]]></phpcode>
</plugin>

Is there any other way to load your css template?

In several articles I found this code, but everyone says outdated


<plugin active="1" executionorder="5">
<title>CSS - Inject CSS into vBulletin</title>
<hookname>css_start</hookname>
<phpcode><![CDATA[if(in_array('vbulletin.css',$matches[1]))
{
$matches[1][] = 'ct_thread.css';
}]]></phpcode>
</plugin>

Thanks

Regards

Lynne
08-24-2011, 03:11 PM
Take a look at the headinclude template:
<vb:if condition="$vboptions['storecssasfile']">
{vb:cssfile main-rollup.css}
{vb:raw template_hook.custom_css_links}
<vb:else />
{vb:cssfile bbcode.css,editor.css,popupmenu.css,reset-fonts.css,vbulletin.css,vbulletin-chrome.css,vbulletin-formcontrols.css{vb:raw template_hook.custom_css_list}}
</vb:if>There is an if/else there. You can only use the template hook custom_css_list if the css is not being stored in the file system. So, two different template_hooks need to be defined.


$template_hook['custom_css_links'] .= xxxxxx;
$template_hook['custom_css_list'] .= yyyyyy;

Asterix_ita
08-24-2011, 03:22 PM
Thanks Lynne

I have to replace xxxx and yyy with the name of my template.css, is it correct?

Regards

Lynne
08-24-2011, 03:29 PM
No, not exactly. The _links hook requires a full on link. (I actually got this code from one of BOPs mods.)

Try this:

$template_hook['custom_css_links'] .= '<link rel="stylesheet" type="text/css" href="clientscript/vbulletin_css/style' . str_pad($style['styleid'], 5, '0', STR_PAD_LEFT) . $vbulletin->stylevars['textdirection']['string'][0] . '/ct_thread.css" />';

$template_hook['custom_css_list'] .= ',ct_thread.css';

Asterix_ita
08-24-2011, 03:46 PM
Thanks it works fine.

You know how these two ways of interpreting the CSS code

Regards

Lynne
08-24-2011, 07:50 PM
I have no idea why that gap is there. You'd need to analyze the box using something like firebug.

CvP
11-25-2011, 04:52 PM
I actually got in to some trouble with this a few minutes ago and Lynne was kind enough (as always!) to point me I'm using process_tempaltes_complete instead of parse_templates.

With that help, now I am using this in my codes:


if ($vbulletin->options['storecssasfile']) {
$template_hook['custom_css_links'] .= '<link type="text/css" rel="stylesheet" href="' . vB_Template::fetch_css_path() . 'MY_CSS.css' . '?d=' . $style['dateline'] . '" />';
}
else {
$template_hook['custom_css_list'] .= 'MY_CSS.css';
}

Asterix_ita
11-25-2011, 05:22 PM
Hi CvP

Thanks, but your code works fine on my addon with parse_templates hook, doesn't work with process_tempaltes_complete

regards

CvP
11-25-2011, 11:15 PM
Yes, it needs to be on parse_templates. I used process_templates_complete and banging my head on table until Lynne stepped in.

Boofo
11-26-2011, 12:31 AM
You can only use the template hook custom_css_list if the css is not being stored in the file system. So, two different template_hooks need to be defined.

What hooks would you use if the css IS stored in the file system?

HMBeaty
11-26-2011, 01:40 AM
What hooks would you use if the css IS stored in the file system?
custom_css_links

HMBeaty
12-08-2011, 03:40 AM
Changing this up a bit....in the headinclude template here:
<!--[if lt IE 8]>
{vb:cssfile popupmenu-ie.css,vbulletin-ie.css,vbulletin-chrome-ie.css,vbulletin-formcontrols-ie.css,editor-ie.css}
<![endif]-->
{vb:raw template_hook.headinclude_css}Would it be safe to say we can use the template hook headinclude_css to add on to the -ie.css? For example, I'd like to add sidebar-ie.css to it, but unsure if that would work (since I don't use IE 8).

Also, if we can use that hook location, would we use the same method of adding to the store css as files? Like this maybe? .....
$template_hook['headinclude_css'] .= '<link type="text/css" rel="stylesheet" href="' . vB_Template::fetch_css_path() . 'sidebar-ie.css' . '?d=' . $style['dateline'] . '" />';
Or would it just be....
$template_hook['headinclude_css'] .= 'sidebar-ie.css';
Thanks in advance :D

Lynne
12-08-2011, 04:08 PM
If you want to add something for IE only, you need to put that comment code around it.

HMBeaty
12-09-2011, 01:15 AM
So something like this should work, right?

$template_hook['headinclude_css'] .= '<!--[if lt IE 8]>{vb:cssfile MY_CSS.css}<![endif]-->';
Sorry, haven't been able to think straight the past few days :(

HMBeaty
12-10-2011, 03:16 AM
This appears to work (not sure if it's correct though) .....
$template_hook['headinclude_css'] .= '<!--[if lt IE 8]>
<script type="text/javascript" src="clientscript/vbulletin-threadlist-ie.js?v={vb:raw vboptions.simpleversion}"></script>
<link type="text/css" rel="stylesheet" href="' . vB_Template::fetch_css_path() . 'sidebar-ie.css' . '?d=' . $style['dateline'] . '" />
<![endif]-->';

Boofo
01-17-2012, 08:14 AM
Not to beat a dead horse, but how come the css files don't need to be rendered before you add them to the hooks?

Lynne
01-17-2012, 11:05 PM
Because they are special and dealt with in a different way?

Boofo
01-17-2012, 11:24 PM
Are you guessing? ;)

How's this for posterity, young lady?

// You can only use the template hook custom_css_list if the css is not being stored in the file system.
// So, two different template_hooks need to be defined. The custom_css_links hook requires a full on link.
// Also, this needs to be on the parse_templates hook, not on process_templates_complete. -- Lynne


That is in my first mod using the css hooks. I'll make you famous. ;)

Lynne
01-18-2012, 06:40 PM
Wonderful. Do I get the fortune that comes with being famous?

Boofo
01-18-2012, 07:03 PM
Whatever you want. You know I'm a sucker for your charms. ;)