Get user object (for mail address) in details.tpl template

Hi,
I am desperately trying to get the user`s e-mail address within details.tpl.
For some reason, the obvious approach did not work out as expected.

First I tried Lazy Loading within the template:

[{ if $oxcmp_user }]
oxusername: [{ $oxcmp_user->oxuser__oxusername->value }]
[{ /if }] 

I never get any value, even if the user is definitely logged in.
[{debug}] tells me, that oxcmp_user = true. This Boolean value is all I can find in the debug list.

Then I tried it via a “getter” function
So I modified view.php (of course calling it from details.tpl):


public function getUserMail()
{                 
    $oUser = $this->getUser();
    // also tried alternatively: $oUser = oxNew( 'oxuser' );
    
    if ($oUser)
    {
      error_log("** 1 ". $oUser->oxuser__oxusername->value);
      return $oUser->oxuser__oxusername->value;
    } else {
      error_log("** 2 : ". $oUser->oxuser__oxusername->value);
      return;
    }            
} 

error_log shows for both variants getUser und oxNew) that the oUser object is not set.

Am I missing something here?

I`d appreciate any useful comment!
Thanks

floko

I tried your first approach and it works, email Address is displayed in details.tpl.
[{debug}] tells me, that oxcmp_user = oxUser Object.

That`s very strange… Seems to be a problem caused by some unusual settings.

Thanks for testing and letting me know so quickly! :slight_smile: