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.
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>
Is this for users or usergroups?
FYI, $mybbuser is deprecated and will not work. It's $mybb->user
on my board it still works what are you on about

and i am using 1.2.1
depreciated, doesn't mean removed. It means your not supposed to use it anymore.
i know that only to show how code works anyway

plus will not work with $mybb->user
Doesn't work with 1.2.2 for some reason.
Massacre Wrote:plus will not work with $mybb->user

Why wouldn't it work? o.0