Hi All, I have modified (ShowUserList) a small snippet which I would like to use twice on one page. Well once in a side bar from a template and again on another page showing different details. The problem is when I goto the page which gives me things twice I dont see the entire picture! The code: (please excuse any bad programming practices) [code:]
<?php
// ShowUserList - MODx snippet to display the users assigned to a given web group.
// the webgroup is set in the snippet properties tab or the snippet call.
// &webgroup=webgroup;text;webgroupname
// [[ShowUserList? &webgroup=`webgroupname` &type=`count` &tpl=`mylist`]]
/**
&type parameter.
default: both
option: 1 - count - display a total number only
option: 2 - list - display a list only
&tpl parameter.
default = ''
Optional value for a template chunk name.
**/
// Default template
$deftpl ='<h3>[+count+] Members Registered.</h3>
<ul>[+users+]<ul>';
$type = isset($type) ? $type : 'both';
$tpl = isset($tpl) ? $modx->getChunk($tpl) : '';
$output = $tpl;
// check for valid web user group
if(!isset($webgroup) || $webgroup == '') { return; } // quietly do nothing if webgroup is not set
$result = $modx->db->select('id',$modx->getFullTableName('webgroup_names'),"name = '".$webgroup."'");
if($modx->db->getRecordCount($result) != 1) { return; } // quietly do nothing if webgroup does not exist
$table1 = $modx->getFullTableName('web_users');
$table2 = $modx->getFullTableName('webgroup_names');
$table3 = $modx->getFullTableName('web_groups');
$results = $modx->db->select("tbl1.username", "$table1 AS tbl1, $table2 AS tbl2, $table3 AS tbl3", "tbl2.name='$webgroup' AND tbl3.webgroup=tbl2.id AND tbl1.id = tbl3.webuser", 'tbl1.username ASC');
if ($type == 'count' or $type == 'both') {
$amount = $modx->db->getRecordCount($results);
}
if ($type == 'list' or $type == both) {
$userlist .= '<ul>';
while($users = $modx->db->getRow($results)) {
$userlist .= '<li>'.$users['username'].'</li>';
}
$userlist .='</ul>';
}
$modx->setPlaceholder('count',$amount);
$modx->setPlaceholder('users',$userlist);
return $output;
?>
[[ShowUserList? &webgroup=`webgroupname` &type=`count` &tpl=`mylist` id=`side`]]
$modx->setPlaceholder("$id-count",$amount);
[+side-count+]
<?php
// ShowUserList - MODx snippet to display the users assigned to a given web group.
// the webgroup is set in the snippet properties tab or the snippet call.
// &webgroup=webgroup;text;webgroupname
// [[ShowUserList? &webgroup=`webgroupname` &type=`count` &tpl=`mylist` &id=`new`]]
// You can also put [+count+] and [+users+] placeholders in the body of your content and it will still work.
// When you use &id pleae prefix your placeholders and seperate them with .
// Ex: [[ShowUserList? &id='new' &webgroup=`Registered Users`]]
// [+new.count+] [+new.users+]
/**
&type parameter. (default: both)
option: 1 - count - display a total number only
option: 2 - list - display a list only
&tpl parameter. (default = '')
Optional value for a template chunk name complete with placeholders.
&id parameter
Optional name to add to placeholders to allow for multiple uses on a webpage.
**/
// Default template
$deftpl ='<h3>[+count+] Members Registered.</h3><br /><ul>[+users+]<ul>';
$type = isset($type) ? $type : 'both';
$id = isset($id) ? $id : '';
$tpl = isset($tpl) ? $modx->getChunk($tpl) : '';
$output = $tpl;
// check for valid web user group
if(!isset($webgroup) || $webgroup == '') { return; } // quietly do nothing if webgroup is not set
$result = $modx->db->select('id',$modx->getFullTableName('webgroup_names'),"name = '".$webgroup."'");
if($modx->db->getRecordCount($result) != 1) { return; } // quietly do nothing if webgroup does not exist
$table1 = $modx->getFullTableName('web_users');
$table2 = $modx->getFullTableName('webgroup_names');
$table3 = $modx->getFullTableName('web_groups');
$results = $modx->db->select("tbl1.username", "$table1 AS tbl1, $table2 AS tbl2, $table3 AS tbl3", "tbl2.name='$webgroup' AND tbl3.webgroup=tbl2.id AND tbl1.id = tbl3.webuser", 'tbl1.username ASC');
if ($type == 'count' or $type == 'both') {
$amount = $modx->db->getRecordCount($results);
}
if ($type == 'list' or $type == both) {
$userlist .= '<ul>';
while($users = $modx->db->getRow($results)) {
$userlist .= '<li>'.$users['username'].'</li>';
}
$userlist .='</ul>';
}
//placeholder definition
if ($id !='') {
$count .= $id.'.count';
$users .= $id.'.users';
} else {
$count = 'count';
$users = 'users';
}
$modx->setPlaceholder($count,$amount);
$modx->setPlaceholder($users,$userlist);
return $output;
?>