If you're going to use a snippet, why not do the whole task there and cut down on the overhead?
/* ShowUsername snippet */
$output = "";
if ($modx->user->get('id') == 0) {
$output = 'Guest';
} else {
$output = $modx->user->get('username');
}
return $output;
Or, with the option to show the full name:
[[!ShowUsername? &fullName=`1`]]
/* ShowUsername snippet */
$output = "";
$fullName = $modx->getOption('fullName', $scriptProperties, false);
if ($modx->user->get('id') == 0) {
$output = 'Guest';
} else {
if ($fullName) {
$profile = $modx->user->getOne('Profile');
if ($profile) {
$output = $profile->get('fullname');
}
} else {
$output = $modx->user->get('username');
}
}
if (empty($output)) {
$output = $modx->user->get('username');
}
return $output;