MyBB Community Forums

Full Version: Decision making..
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
It seemed like a really simply thing to do but so far I just keep hitting a brick wall.

All I want to do is to create a custom page that I can edit in templates (which is fine and easily done) which then can display different options/content depending upon the user id and/or group of the member viewing the page.

I started with this sort of thing..

if({$mybb->user['uid']} = 1){

do something;
}

But it doesn't work. And neither does anything else I try.

Please help..
Are you creating a completely new page in php? Or just in the templates? If it's in php you need to require once global.php and set the globals $mybb and $db.
In this example I was using an existing template to experiment with. I could use the {$mybb->user['uid']} variable and print it out so I knew it was correct but for the life of me I just couldn't get the if statement to make any sense with it.
Without a plugin you can only display variables inside templates, you cannot include PHP code.

For your needs you could create a new PHP page, following the advice of Jammerx2 and "need to require once global.php and set the globals $mybb and $db."
Fair enough Smile And thanks..

How then, can I use java inside a template to make decisions based upon the mybb variables such as {$mybb->user['uid']}? Because as I said, if({$mybb->user['uid']} = 1){ doesn't work Confused
comparisons in PHP need to be == not just =

if({$mybb->user['uid']} == 1){

do something;
}
Thanks

But how can I use php variables in a template using java?
Basically, I want to write in javascript in a template that can use the mybb variables and make decisions based on them.

Such as

if userid=1
do this
else
do something else
end;

But java can't make any sense of the mybb variables..
As an example, I'm trying to get the following to work in the header_welcomeblock_member_admin template.

&mdash; <a href="{$mybb->settings['bburl']}/{$config['admin_dir']}/index.php">{$lang->welcome_admin}</a>

<script type="text/javascript">
var userid = "<?php echo $mybb->user['uid'] ?>";

if(userid == "1"){
document.writeln('Hello User One') ;
}
else{
document.writeln('You're Not User One!!');
}
</script>

But it won't.. Sad
Why you need the php tag for that? How about this?

var userid = "{$mybb->user['uid']}";
(2009-12-16, 05:52 PM)RateU Wrote: [ -> ]Why you need the php tag for that? How about this?

var userid = "{$mybb->user['uid']}";

I think you might be a genius Cool
If you need to use php in templates take a look at this.
http://community.mybboard.net/thread-31860.html

You would use php tags like <?php if($mybb->user['uid'] = 1) { echo Hello } ?>