MyBB Community Forums

Full Version: PHP in templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everybody,

I change my ex-PunBB forum for a MyBB and I have only a problem with templates :

PHP don't work in my header. This the php code :

<?php
$id = $mybb->user['uid'];
$gid = $mybb->user['usergroup'];
$username = $mybb->user['username'];
if ($gid== "1") // Si pas loggé, affichage du choix de login



    {



    $loginbox='<a href="register.php">Cr&eacute;er un compte</a> | <a href="http://www.acoustik.fr/login">Identification</a><span> | <a href="login.php?action=forget">Mot de passe oubli&eacute;</a>';

    $forumbox='<a href="">Forum</a> | <a href="userlist.php">Liste des Membres</a> | <a href="misc.php?action=rules">R&egrave;gles</a> | <a href="search.php">Recherche</a> |  <a href="register.php">Inscription</a>';

    }







else // sinon ok



    {



    $loginbox='Bienvenue, <strong>'.$username.'</strong> | <a href="profile.php?id='.$id.'">Votre Profil</a> | <a href="pms_list.php">MP</a> | <a href="login.php?action=out&id='.$id.'">Deconnexion</a>';

$forumbox='<a href="http://www.acoustik.fr/forum">Forum</a> | <a href="userlist.php">Liste des Membres</a> | <a href="misc.php?action=rules">R&egrave;gles</a> | <a href="search.php">Recherche</a>';


    if ($gid =="4" OR $gid =="12" OR $gid =="13")



        {



         $loginbox.= ' | <a href="http://www.acoustik.fr/admin.php">R&eacute;dacteurs</a>';



        }

    

    if ($gid=="4")



        {



         $forumbox.= ' | <a href="admin_index.php">Administration Forum</a>';



        }

    }
?>
Sorry it's in french but you can understand I think. If you want me to translate, no problem...

I saw that to put PHP on template, you have to put your script between {}

But how I can do with my If{} ?

Thx a lot Smile
you can't use php in the templates
labrocca was hoping to get this idea passed for the next version, or 1.4 of MyBB:
http://ideas.mybboard.net/idea/template-conditionals


Dr Small
You'll just need to modify the appropriate templates *header_welcomeblock_guest, header_welcomeblock_member & header_welcomeblock_member_admin* with what you want each group to see!
You can never use php in templates. Anyway php code should be added to the php files, now as we are welcome with header templates and welcome messages you will need to edit global.php file with any php code you need to use, and then use your variables mentioned there in any of those templates you want.

However i can see you are trying to change things in the welcome block.. see what Judel said and reply.