PDA

View Full Version : Forumhome Forumbit HELP!


Michael Morris
08-10-2004, 12:15 AM
Hey. I'm having trouble getting a template mod to work with the 4 forumhome forumbit templates. Basically, I want to give my users the ability to turn off forum icons in my forum listings to save bandwidth. Unfortunately the system always evaluates the following to false.


<if condition="$forum['icon'] AND $extrauseroptions['display_forumicon']">
Display the forum icon code goes here.


Now, forum icon is defined by the database through a hack. It works fine BY ITSELF. The $extrauseroptions array is defined in the phpinclude_start template.

Now I've used this kind of conditional in $threadbit, $header, $navbar, $FORUMHOME with NO PROBLEMS WHATSOEVER!!! Why is the system failing to recognize this variable in these four templates.

NOTE: I *suspect* it has to do with variable scope, but if that's the case WHY ONLY HERE?? Why haven't I seen this occur in $threadbit, postbit, etc??

-- Getting incredibly fustrated here, Mike.

Modin
08-10-2004, 12:27 AM
try removing the single quotes, I don't believe you can have them in a conditional


<if condition="$forum[icon] AND $extrauseroptions[display_forumicon]">
Display the forum icon code goes here.

Michael Morris
08-10-2004, 01:18 PM
try removing the single quotes, I don't believe you can have them in a conditional


<if condition="$forum[icon] AND $extrauseroptions[display_forumicon]">
Display the forum icon code goes here.


Wrong answer - it won't compile at all if you remove them.

The syntax is correct - it works in EVERY TEMPLATE EXCEPT the four forumhome_forumbits. WHY?

CarCdr
08-10-2004, 01:36 PM
I presume you have verified the values by outputting them to the page. For instance, you say that "$forum['icon']" works, so I presume you sent it to the page to verify its contents for each forum. Did you do the same for "$extrauseroptions" to verify that it contains nothing?

Post the code that sets "$extrauseroptions".

Michael Morris
08-10-2004, 04:18 PM
I presume you have verified the values by outputting them to the page. For instance, you say that "$forum['icon']" works, so I presume you sent it to the page to verify its contents for each forum. Did you do the same for "$extrauseroptions" to verify that it contains nothing?

Post the code that sets "$extrauseroptions".

$forum['icon'] works by itself. That is

<if condition="$forum['icon']">code</if>

works without a hitch. It's output can be seen in the images it fetches.

I've run tests where I simply typed

$extrauseroptions['display_forumicon'] = true;

And it didn't work. I've echo'ed the variable at the end of the phpinclude_end template and it's came back as 1, which is normal for a boolean.

The only thing I can think of is that it's simply not being *seen* by the section of code that parses those templates and I need to make the variable global in scope somehow. Short of adding it's value to $GLOBALS I don't know how (and I've never had to worry about variable scope before with vbulletin so I'm not too sure even then).

Modin
08-10-2004, 04:20 PM
Try this
<if condition="$forum[icon] == 1 AND $extrauseroptions[display_forumicon] == 1">
Display the forum icon code goes here.


I've used that a 1000 times (without the quotes too) and it's always worked...as long as you set $extrauseroptions before the template is called.

It would only be a scope problem if $extrauseroptions was set in a function and wasn't returned, nor set to global within the function.

AN-net
08-10-2004, 05:16 PM
it could be because that template is used in a file that does not use those variables;)

Michael Morris
08-10-2004, 07:58 PM
No, in PHP functions can't see variables outside themselves unless they are declared as global. So if the forumbit templates are evalutated by a function...

I tried directly linking to $bbuserinfo, no go there either, and as far as I know that's a vbulletin global... So I give up.

And let me repeat for those who didn't read it the first time: $forum['info'] works by itself. Therefore the problem MUST BE in the second variable. I've altered the code to print the value of the variable - and sure enough it's null in those templates only even when it has a value elsewhere.

Modin
08-11-2004, 04:24 PM
^^ that's exactly what I said ;)

try this, open up functions_forumlist.php and find

function construct_forum_bit($parentid, $depth = 0, $subsonly = 0)
{


after it add

global $extrauseroptions;

Michael Morris
08-11-2004, 06:59 PM
Ok, I'll try that tomorrow. Right now my setup is under executive review - I dare not hack something and cause a parse error. Thx.

Michael Morris
08-12-2004, 02:02 AM
^^ that's exactly what I said ;)

try this, open up functions_forumlist.php and find

function construct_forum_bit($parentid, $depth = 0, $subsonly = 0)
{


after it add

global $extrauseroptions;


I didn't even try this because I looked below it and saw that $bbuserinfo is declared global. When I tried this conditional with $bbuserinfo it failed, so I now I am completely out of ideas. :(

Modin
08-12-2004, 03:13 AM
well, since you know $forum is being displayed correctly, how about tagging your new option on to that array?


$forum[display_forumicon] = ...


just make sure it's tagged on before the forumlist is called.