MyBB Community Forums

Full Version: php code in template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I have a custom header that needs to display different information depending on whether or not a user is logged in.

I have inserted my header code into the 'header' template, and all the HTML comes out fine. The php, 'if-else' part does not though.

This is the basically the code I need:

<?php
if(!$mybb->user['uid']){ //if user is not logged in
    echo '<li><a href="http://mysite.com/forums/member.php?action=login">Login</a></li>';
} else {
    echo '<li><a href="/forums/member.php?action=logout&amp;logoutkey='.{$mybb->user['logoutkey']}'">Logout</a></li>';
}
?>

and this is what that outputs:

Login'; } else { echo'Logout';}?>

Can we use PHP code in the templates? If not, how can get this conditional behavior to work?

Thanks
Thanks, I installed the plugin and changed my code to this:

<if !$mybb->user['uid'] then>
    <li><a href="http://mysite.com/forums/member.php?action=login">Login</a></li>
<else />
    <li><a href="/forums/member.php?action=logout&amp;logoutkey='.{$mybb->user['logoutkey']}'">Logout</a></li>
</if>

Works perfectly