MyBB Community Forums

Full Version: If conditions in templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Anyone here using the "if" conditions through the vB modifications?

Anyways, I'm trying to use it so I can have a notice shown only to those who haven't activated their accounts yet. I tried
<if condition=$mybb->usergroup['gid']== 5 <then>

TEXT HERE

		<else /></if>	

Anyways, works fine when gid is 1, but not with 5.

Just wondering if anyone else has tried this.
I wish they would add conditional support to templates in 1.4. Eventually this really needs to be done.
I agree totally.

It's one of the reasons I don't like Coppermine and would move in favor of more integrated solution for MyBB.
i think that it may be due to the space that it doesnt like it, well that happens in some that it is the space that means it doesnt work.
Let me ask you guys something...

What is the point with <then>?

It doesn't do anything really...

MyBBT has their own Conditional Mod in place and it works fine without the <then> thing.

Btw, we do plan on releasing this. Wink
Ryan Ashbrook Wrote:Let me ask you guys something...

What is the point with <then>?

It doesn't do anything really...

MyBBT has their own Conditional Mod in place and it works fine without the <then> thing.

Btw, we do plan on releasing this. Wink

I don't know, dude. I just took the example from other areas (default ones to the modification and theme) and went with it. [shrug]

My knowledge is limited. I take examples, duplicate them and then customize them to my needs.
in inc/functions.php

Find


/**
 * Outputs a page directly to the browser, parsing anything which needs to be parsed.
 *
 * @param string The contents of the page.
 */

add under

// ###################### Start iif #######################
function iif($expression, $returntrue, $returnfalse = '')
{
return ($expression ? $returntrue : $returnfalse);
}
// #############################################


in inc/class_templates.php

find


$template = str_replace("\\'", "'", $db->escape_string($template));

add under

$template= str_replace("<if condition=","\".iif(",$template);
$template= str_replace("<then>",",\"",$template);
$template= str_replace("<else />","\",\"",$template);
$template= str_replace("</if>","\").\"",$template);





code is

<if condition=$mybbuser['uid']== 1 <then>
Other Users <else /> Is User 1 </if>
The then is there for a reason of course.
using <if condition=$mybbuser['uid']== 1 <then> <whatever_code_should_appear> </if>
returns in php iif($mybbuser['uid'] == 1, <whatever_code_should_appear> );