php – smarty get data from $globals – Education Career Blog

If have used {debug} to see what data i can access in a page.
Now the stuff i need sit’s in {$GLOBALS} like

   current_user => Array (17)
      id => 3759
      user_name => bla
      email => [email protected]
      group => Array (2)
        id => users
        caption => Users

But how to i get the data i need to show on my page? Like the e-mail adress?


If you’ve only access to the template file, you could assign $GLOBALS to a smarty var $globals like this:

{php}$this->assign('globals', $GLOBALS);{/php}

$this refers to the active Smarty object.

A better way to implement this, when having access to the PHP script, would be:

$somevar = 'this is a test';
$tpl = new Smarty;
$tpl->assign('globals', $GLOBALS);

Template file:


Optionally use a filter like:



I guess this may work:


echo $GLOBALS’current_user”email’;


(This is not the best way. You will need to make sure that the data is escaped before output, so you can use htmlentities() or better to assign the data in your code, see:

Leave a Comment