PDA

View Full Version : How to phrase part of a conditional statement?


bzcomputers
10-01-2012, 04:35 PM
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:

<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:
<vb:if condition="!in_array($GLOBALS['forumid'], array({vb:rawphase special_forums))">


But that just gives this error:
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?

kh99
10-01-2012, 04:44 PM
If you're setting an array called $special_forums in a plugin, like maybe:

global $special_forums;
$special_forums = array(23, 24, 25, 26, 27, 28, 49, 77);



then you can do this:
<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.

bzcomputers
10-01-2012, 06:11 PM
So, if I needed the plugin to be available for multiple templates - postbit, SHOWTHREAD, newthread.

Will I need multiple plugins?

kh99
10-01-2012, 08:24 PM
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).

bzcomputers
10-01-2012, 08:58 PM
I still getting an error with the conditional statement you posted above:

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:

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

all still give same error.

kh99
10-01-2012, 09:04 PM
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.

bzcomputers
10-01-2012, 09:15 PM
The error when I try to save is this:

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:

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.

kh99
10-01-2012, 09:25 PM
OK, I just tried this and it works (at least as far as being valid template syntax):

<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.

bzcomputers
10-01-2012, 09:45 PM
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:

Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3965

these are lines 3962-3978:

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;
}