When a user is logged into the frontend of your site, their username and ID can be accessed by the following Properties:
1 [[+modx.user.id]] - Prints the ID
2 [[+modx.user.username]] - Prints the username
If a user is not logged in, ID will be blank, and Username will be "(anonymous)".
Although if you want a pre-built add-on, this would probably do the job:
http://modx.com/extras/package/personalize
-
- 72 Posts
So how would I create a if statement using this method.?
-
- 72 Posts
There is a problem when I tried to use [[+modx.user.username]] in an echo it printed a username instead of anonymous. And I was not logged in on the front end.
It was probably printing your Manager username.
As a general rule, snippets should never print or echo output. Due to the way snippets are processed, this can lead to unexpected results. And since they are basically functions, they should always return.
<?php
$username=$modx->user->get('username');
$userPass=$modx->user->get('password');
if ($username != '(anonymous)' ){
$output = 'My Account';
}if ($username==='(anonymous)'){
$output = 'Login';
}
return $output;