Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
  #1  
Old 10-01-2012, 04:35 PM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to phrase part of a conditional statement?

I have a conditional statement that I'm using in multiple templates numerous times.

It contains an array of forum ids that I want to display differently than the standard forums.

Everything works well using this conditional:

Code:
<vb:if condition="!in_array($GLOBALS['forumid'], array(23, 24, 25, 26, 27, 28, 49, 77))">

The probem I want to avoid is if I want to add another forum to this list, as of now I will have to go back, find, and then edit every single conditional individually.

I've tried to phrase the array like this:
Code:
<vb:if condition="!in_array($GLOBALS['forumid'], array({vb:rawphase special_forums))">

But that just gives this error:
Quote:
The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.

Anyone have a solution?
Reply With Quote
  #2  
Old 10-01-2012, 04:44 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you're setting an array called $special_forums in a plugin, like maybe:
Code:
global $special_forums;
$special_forums = array(23, 24, 25, 26, 27, 28, 49, 77);

then you can do this:
Code:
<vb:if condition="!in_array($GLOBALS['forumid'], $GLOBALS['special_forums'])">

It looks like you were trying to us a phrase to list the forums? That won't work because the part inside the condition is php code, and it won't parse the template tags.
Reply With Quote
  #3  
Old 10-01-2012, 06:11 PM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So, if I needed the plugin to be available for multiple templates - postbit, SHOWTHREAD, newthread.

Will I need multiple plugins?
Reply With Quote
  #4  
Old 10-01-2012, 08:24 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, you just need to use a hook that's executed for every page, like one of the global_* hooks (Edit: or parse_templates. That's probably a good one since it's called once before any templates are used).
Reply With Quote
  #5  
Old 10-01-2012, 08:58 PM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I still getting an error with the conditional statement you posted above:

Quote:
The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
I've tried a few different options:

Code:
<vb:if condition="!in_array $GLOBALS['forumid'], $GLOBALS['special_forums']">
Code:
<vb:if condition="!in_array ($GLOBALS['forumid'], $GLOBALS['special_forums'])">
all still give same error.
Reply With Quote
  #6  
Old 10-01-2012, 09:04 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I did leave out a closing paren, which I just went back and inserted. But it looks like the second one you posted above should work (of course you need the closing </vb:if> somewhere as well).

What is the error you're getting? If it's an error when you try to save the template you might want to try taking out the if and see if you still get the error.
Reply With Quote
  #7  
Old 10-01-2012, 09:15 PM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The error when I try to save is this:

Quote:
The following error occurred when attempting to evaluate this template:
%1$s
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.

If I remove the "if" the error is this:

Quote:
The following error occurred when attempting to evaluate this template:
Invalid Tag Nesting
This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
Reply With Quote
  #8  
Old 10-01-2012, 09:25 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, I just tried this and it works (at least as far as being valid template syntax):

Code:
<vb:if condition="!in_array ($GLOBALS['forumid'], $GLOBALS['special_forums'])">
Stuff here
</vb:if>

So it's possible that you have something else wrong in the template. The second error does say something about "invalid tag nesting", so if you took out only the <vb:if ...> tag but not the corresponding </vb:if> then that might be why.
Reply With Quote
  #9  
Old 10-01-2012, 09:45 PM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Alright I'll see if I can't figure out why it still won't work on my end.

I forgot to post that the error is referenced at:

Quote:
Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3965
these are lines 3962-3978:

Code:
function fetch_error_array($errors)
{
	$compiled_errors = array();
	foreach ($errors as $key => $value)
	{
		if (is_string($value))
		{
			$compiled_errors[$key] = fetch_error($value);
		}
		else if (is_array($value))
		{
			$compiled_errors[$key] = call_user_func_array('fetch_error', $value);
		}
	}

	return $compiled_errors;
}
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:40 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04449 seconds
  • Memory Usage 2,233KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (8)bbcode_code
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete