Right. You want a username to be displayed exactly like Ditto does it.
It turns out Ditto has a natty little function that calls the right user table etc. At first I nicked the function and put it into a snippet. It worked great, but then I realised that it was probably better all around to just reuse the function that is sat in a class on your hard drive. So I stripped the class loader from Ditto, added the two function parameters to the snippet, and then passed them to the function.
Add this to your news item templates:
[!UsernameLikeDitto? &createdby=$createdby!]
And add this snippet called UsernameLikeDitto
/* Snippet Name: UsernameLikeDitto
* Short Desc: Enables use of Ditto's getcreatedby function. Requires Ditto.
* Author: The MODx Project / Paul Gregory
* Version: 0.1
* Last Edited: 03-Jul-2006
* Function: Enables use of Ditto's nice Get User Name function getcreatedby outside of Ditto.
*
*/
// ---------------------------------------------------
// Get Language
// ---------------------------------------------------
$language = (isset($language))? $language : "english";
// ---------------------------------------------------
// Include files
// ---------------------------------------------------
$files['language'] = "assets/snippets/ditto/lang/$language.inc.php";
$files['functions'] = "assets/snippets/ditto/ditto.class.inc.php";
foreach ($files as $filename => $filevalue) {
if (file_exists($filevalue) && $filename != "language") {
include_once($filevalue);
} else if(file_exists($filevalue) && $filename == "language") {
include_once($filevalue);
} else if($filename == "language") {
return "Language file does not exist Please check: ".$filevalue;
} else {
return $filevalue.$_lang['file_does_not_exist'];
}
}
if (class_exists('ditto')) {
$ditto = new ditto();
} else {
return $_lang['invalid_class'];
}
// ---------------------------------------------------
// Parameters
// ---------------------------------------------------
$createdby = isset($createdby )? $createdby : 0;
// ID in
$format = isset($format)? $format: "html";
// cribbed from ditto function getcreatedby
$output = $ditto->getcreatedby($createdby, $format);
return $output;
Please let me know if it works for you. I’ve not been able to test it on anything with multiple users but I can’t see why it won’t work.