On MODX Forums sometimes I discover Snippets that are quite useful, but nobody knows about them because they're hidden somewhere, usually in old threads that are difficult to find. I think it's a shame that so many Snippets are not available to MODX Developers and MODX Designers. That's why, from now on, I will try to publish them on this blog.
One of these Snippets, for example, allow us to get the fullname of the user that has created a Resource. This can become handy if you are building a blog and you need the author's name, because you can output it on the page. Note: this Snippet has been modified to work with Ditto templates.
1. Installation
On MODX Manager, go to "Elements > Manage Elements >
Snippets > New Snippet":
Snippet Name: author.
Snippet Description: Get Author Fullname.
Snippet code (php):
<?php $editedby_id = empty($id_author) ? $modx->documentObject['createdby'] : $id_author; // sample conversion $user_info = $modx->getUserInfo($editedby_id); $editedby_name = ($user_info['fullname'] ? $user_info['fullname'] : $user_info['username']); return $user_info['fullname']; ?>
2. Usage
You can use the Snippet in this way:
<div class="author-info">Posted by [[author]]</div> <!-- Get author fullname from the Resource --> <div class="author-info">Posted by [[author? &id_author=`[+createdby+]`]]</div> <!-- Get author fullname from a Ditto template -->
3. Credits
I don't remember where I have found this Snippet so I can't provide a link to the original version. I tried to search the code on Google but I couldn't find anything, if you know where it is contact me and I'll add credits.
Furthermore, if you happen to find useful Snippets on MODX Forums, send me the link and I'll publish them on this blog.


Keith Penton
:) KP