PDA

View Full Version : Convert template conditional into plugin code


Mark.B
03-07-2009, 12:25 PM
Hi

I have the following template conditional, variants upon which I use quite a lot:
<if condition="!in_array($foruminfo['forumid'], array(1,2,3,4))">

I can work out how to format most conditionals if they are needed in php plugin code rather than in a template. However, I am unsure how to do this for the in_array stuff.

How would I format the above conditional to make it apply to a block of plugin code? (Assuming it's at a hook where $foruminfo is available).

Lynne
03-07-2009, 04:00 PM
Actually, that one if pretty much the same in php:

if (!in_array($foruminfo['forumid'], array(1,2,3,4)))(Sometimes you need to change $foruminfo to $forum or $thread or $threadinfo, depending. Sometimes you can even just use $forumid instead of $foruminfo['forumid'])

Mark.B
03-07-2009, 04:27 PM
Thanks Lynne....I needed that as previously I was using something like
if ($forum['forumid'] != 1 AND $forum['forumid'] != 2 AND $forum['forumid'] != 3 AND $forum['forumid'] != 4)
Not sure if that's the exact syntax as I've just typed it from memory, I've deleted it now. But you get the idea.

It was working but I felt it was ridiculously long winded, and I had read somewhere it used marginally more resources doing it that way.

Dismounted
03-08-2009, 04:46 AM
It was working but I felt it was ridiculously long winded, and I had read somewhere it used marginally more resources doing it that way.
The difference would be negligible, unless you're processing a lot of comparisons.