Log in

View Full Version : Dynamically alter $stylevar['codeblockwidth']


Antivirus
06-19-2008, 04:33 PM
I have been trying to dynamically alter the width of $stylevar['codeblockwidth'] based upon a condition in php, however it's not behaving as expected. It's just stretching to the max width to fit all the contents within the code tags.

I am inserting the following code into hook group_complete

$stylevar['codeblockwidth'] = $vbulletin->options['scst_rightgblockwidth'];


Anyone know why it's not working?

Opserty
06-19-2008, 05:29 PM
Have you checked the PHP code around the hook, it might give you clues.

Maybe the variable names are incorrect or something?

Where is the hook located? (I haven't used/come across it before)

Antivirus
06-19-2008, 05:36 PM
the hook's located within group.php

I'm thinking it's something to do with bbcode being parsed at adifferent time than template output. Problem is though that template bbcode_code is cached way before any php runs at all, which might be a problem as well...

Boofo
06-19-2008, 05:36 PM
You need to add it to global_start. That is where I am doing the same type thing.

if (is_browser('ie'))
{
if (THIS_SCRIPT != 'private')
{
$stylevar['codeblockwidth'] = "890px";
}
else
{
$stylevar['codeblockwidth'] = "745px";
}
}

I have it set to auto in the skin.

Antivirus
06-19-2008, 05:48 PM
Boofoo, That would work for me if I just needed to modify it to the same size, all the timje, however since it's being modified based upon a conditional within the $group array, that's too soon...

But seeing your code did help me figure out the problem... the issue was that the template bbcode_code sets the width using $stylevar['codeblockwidth'] as expected, but the 'px' isn't included in the template, it is included in the var... so the following works as expected within hook group_complete


switch($sc_gblock['position'])
{
case 'left':
{
$stylevar['codeblockwidth'] = ($vbulletin->options['scst_leftgblockwidth'] - 60) . 'px';
}
break;
case 'right':
{
$stylevar['codeblockwidth'] = ($vbulletin->options['scst_rightgblockwidth'] - 60) . 'px';
}
break;
}

Boofo
06-19-2008, 05:53 PM
What is the minue 60 for? I set the width to auto as FF handles that fine. It is just IE that gets messed up with auto. I could have dione it with a setting variable but since I am only doing it in one skin, I hard-coded it.

Antivirus
06-19-2008, 06:20 PM
I'm using the - 60 to make ensure that the code is less than the width of the cell, which is set using $vbulletin->options['scst_leftgblockwidth']

Boofo
06-19-2008, 06:33 PM
So this is part of a larger hack then and not just for the width?