I couldn't find a plug-and-play solution to get the current user's profile information in MODX Revolution, so I wrote this very simple snippet to achieve just that. There may be a package that accomplishes this, but my search didn't return anything.
Anyway here it is. I called it
currentUser
Usage:
[[!currentUser? &field=`email`]]
[[!currentUser? &field=`color` &extended=`1`]]
Snippet
<?php
/**
* currentUser
*
* A simple snippet that returns profile and extended fields of the current user logged into the frontend
* For a full list of fields see here: http://rtfm.modx.com/revolution/2.x/administering-your-site/security/users
*
* @ author Treigh Pugh
* @ copyright 2014 Treigh Pugh
* @ version 1.0.0 - December 28, 2012
* @ MIT License
*
* OPTIONS
*
* field - The field to retrieve - defaults to fullname.
* extended - (Opt) Set to true to get extended fields.
*
* Usage:
*
* [[!currentUser? &field=`email`]]
* [[!currentUser? &field=`color` &extended=`1`]]
*
**/
// Set defaults
$field = $modx->getOption('field', $scriptProperties, 'fullname');
$extended = $modx->getOption('extended', $scriptProperties, false);
$profile = $modx->user->getOne('Profile');
if ($extended) {
// If &extended=`1`, get extended fields
$fields = $profile->get('extended');
$output = $fields[$field];
} else {
// Else, just get profile fields
$output = $profile->get($field);
}
return $output;
Please suggest any improvements or alternatives if necessary.