vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Use $foruminfo[forumid] In_Array in BBCode (https://vborg.vbsupport.ru/showthread.php?t=298055)

ExcelFox 05-11-2013 07:54 PM

Use $foruminfo[forumid] In_Array in BBCode
 
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

Code:

<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

Quote:

Originally Posted by kh99 (Post 2421387)
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 [DATE]1368309819[/DATE] at [TIME]1368309819[/TIME] ---------------

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 [DATE]1368310619[/DATE] at [TIME]1368310619[/TIME] ---------------

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

Quote:

Originally Posted by ExcelFox (Post 2421399)
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 [DATE]1368310619[/DATE] at [TIME]1368310619[/TIME] ---------------

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 [experiment] kkk [/experiment]

Code:

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

kkk yes $foruminfo[forumid]

--------------- Added [DATE]1368315733[/DATE] at [TIME]1368315733[/TIME] ---------------

Quote:

Originally Posted by kh99 (Post 2421411)
BTW, in_array() is allowed in a template conditional (according to the manual anyway).

Maybe it was vB3 that didn't allow that


All times are GMT. The time now is 05:35 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01122 seconds
  • Memory Usage 1,738KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete