PDA

View Full Version : Use $foruminfo[forumid] In_Array in BBCode


ExcelFox
05-11-2013, 07:54 PM
I am trying to use the following conditional in the BBCode

<vb:if condition="in_array($foruminfo[forumid], array(1,2)) AND $bbuserinfo[userid]">

If works fine if the $bbuserinfo[userid] is used alone. However, I can't get the forumid bit to work. I have disabled post caching.

For some reason, $foruminfo[forumid] is returning 0. Well, to put it another way, in_array($foruminfo[forumid], array(0,1,2)) is true no matter which forum I am on, and in_array($foruminfo[forumid], array(1,2) is false, no matter which forum I am on. Any ideas how I can get this to work for forum ids, 1 and 2, and for all other forum ids, go to the else conditional?

nerbert
05-11-2013, 08:27 PM
I could be wrong about everything here, but .............

I don't think you can use in_array() in a conditional, so try

<vb:if condition="($foruminfo[forumid]==1 OR $foruminfo[forumid]==2) AND $bbuserinfo[userid])>

I don't think any of the usual variables are available in bb code, but if $bbuserinfo is available maybe I'm wrong.

You might try
$vbulletin->foruminfo[forumid] instead of $foruminfo[forumid] and likewise $vbulletin->bbuserinfo[userid], and see if that helps.

kh99
05-11-2013, 08:47 PM
Or if those don't work, try $GLOBALS['forumid'].

I'm confused about the question because you normally can't use template tags in a bbcode, but it sounds like it's working in your case (otherwise you'd always see whatever is between the tags).

ExcelFox
05-11-2013, 08:49 PM
nerbert, thanks for your reply..

Yes, normally you won't have any of the usual variables in the bbcode. having said that, there is a mod available here somewhere that allows usage of those variables within the bbcode. Otherwise, I wouldn't have been able to use $bbuserinfo[userid] either. I'll give your suggestion a try.

nerbert
05-11-2013, 08:51 PM
Or if those don't work, try $GLOBALS['forumid'].

I'm confused about the question because you normally can't use template tags in a bbcode, but it sounds like it's working in your case (otherwise you'd always see whatever is between the tags).

I'm experimenting around and it seems you CAN use $foruminfo in conditionals but things like {vb:raw bbuserinfo.userid} don't work

ExcelFox
05-11-2013, 08:52 PM
Kevin, will try your code too. Again, to my point above, there's a mod available here somewhere that allows you to use template tags in a bbcode. I can't seem to find it now. So yeah, if you check my forum www.excelfox.com, you'll see that unless you are a registered user, you won't be able to see the contents of within the code tags. So yeah, it IS working with $bbuserinfo[userid], but not with the tag I mentioned in my original post.

--------------- Added 1368309819 at 1368309819 ---------------

Alright, GLOBALS has done the trick. foruminfo doesn't seem to work. It always returns zero! Thanks a lot Kevin. Thanks for nerbert also for looking at this. Cheers mates.

nerbert
05-11-2013, 09:06 PM
I'm sure $foruminfo[forumid] is available for conditionals

In my experiment <vb:if condition="$foruminfo[forumid]>0">yes</vb:if> returns "yes". I think you just have to work around not being able to use in_array().

ExcelFox
05-11-2013, 09:12 PM
Strange. Though I don't know how GLOBALS and foruminfo are different, I was also under the impression that foruminfo should work. For some reason, <vb:if condition="$foruminfo[forumid]>0">yes</vb:if> doesn't work for me!!

--------------- Added 1368310619 at 1368310619 ---------------

You sure you're testing it within the BBCODE? For the life of me, I cannot get $foruminfo[forumid] to work!!!

kh99
05-11-2013, 09:53 PM
This is one of those questions that gets asked occasionally. Apparently $foruminfo[forumid] doesn't work everywhere, but $GLOBALS['forumid'] seems to do it. Also, you can't use any variables in a template that haven't been registered, so even if $foruminfo exists, it probably wouldn't work in your situation (I assume nerbert is testing using another template, which is why it works). $GLOBALS[] is a "superglobal" so it's available everywhere.

BTW, in_array() is allowed in a template conditional (according to the manual anyway).

nerbert
05-11-2013, 10:34 PM
Strange. Though I don't know how GLOBALS and foruminfo are different, I was also under the impression that foruminfo should work. For some reason, <vb:if condition="$foruminfo[forumid]>0">yes</vb:if> doesn't work for me!!

--------------- Added 1368310619 at 1368310619 ---------------

You sure you're testing it within the BBCODE? For the life of me, I cannot get $foruminfo[forumid] to work!!!

This is the html I'm using for kkk

<div>{param}<vb:if conditon="$foruminfo[forumid]>0"> yes</vb:if> $foruminfo[forumid]</div>

I get

kkk yes $foruminfo[forumid]

--------------- Added 1368315733 at 1368315733 ---------------


BTW, in_array() is allowed in a template conditional (according to the manual anyway).
Maybe it was vB3 that didn't allow that