Log in

View Full Version : No error in array but error with variable?


DislexiK
03-06-2005, 09:50 AM
Hi,

I am currently trying to modify some of the features in vB which only takes effect based on the forum ID. I have:


# In: phpinclude_start

$article_forums = array(4,5);


And in the template(s) I have:

Example template, forumdisplay:

<if condition="in_array($forumid,$article_forums)">
stuff
<else />
other stuff
</if>


However this gives me the following error:

The following error occurred when attempting to evaluate this template:

Warning: in_array(): Wrong datatype for second argument in /includes/adminfunctions_template.php(3096) : eval()'d code on line 4

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.

The funny thing is, when I don't use a variable it works fine:

<if condition="in_array($forumid,array(4,5))">
stuff
<else />
other stuff
</if>

I am guessing this is because the variable is not being parsed?

Any help is appreciated.

Paul M
03-06-2005, 11:08 AM
Just a guess here - but does the variable need to be declared as global ?

DislexiK
03-06-2005, 11:11 AM
There is an error in the title, it is not a variable but an array, and as far as I know I don't think global needs to be defined as I am using other if statements with it and working fine.

For example:

<if condition="$article_forums[0]=4">
stuff
<else />
other stuff
</if>

Works fine

Marco van Herwaarden
03-06-2005, 12:04 PM
Try moving the $article_forums = array(4,5); to the php script, just before th eval of your template, instead of using phpinclude_start.

I think it would work then.

DislexiK
03-06-2005, 12:30 PM
Thanks I figured it out:

Have the forum ID's in a variable in phpinclude_start:

$test = "1,2,3,4,5,6";

And then use this condition in the templates:

<if condition="in_array($forumid, array($test))">
stuff
<else />
other stuff
</if>

For some reason the variable data is only being output in certain places, for example forumhome but not forumhome_forumbit_level1_post.

Is there a reason for this, I thought that phpinclude_start was global?