This question has been answered by BobRay. See the first response.
&totalVar
[[+total]]
[[getResources? &totalVar=`myTotal`]] Output: <strong>[[+myTotal]]</strong>
You can use the propertyin getResources. The placeholder per default is&totalVar[[+total]]
E.g.
[[getResources? &totalVar=`myTotal`]] Output: <strong>[[+myTotal]]</strong>
/** * TotalUsers * * DESCRIPTION * * This Snippet counts the users * * PROPERTIES: * * &useractive integer optional * * USAGE: * * [[!TotalUsers? &useractive=`1`]] * */ $useractive = $modx->getOption('useractive', $scriptProperties,1); // For debugging: $modx->log(modX::LOG_LEVEL_DEBUG , '[TotalUsers] called on page '. $modx->resource->id . ' with the following properties: ' .print_r($scriptProperties, true)); // Verify Inputs if (!isset($scriptProperties['useractive'])) { $modx->log(modX::LOG_LEVEL_ERROR, '[TotalUsers] missing required properties &useractive!'); return; } $output = ''; $users = $modx->getCollection('modUser',array('active'=>$useractive)); if (empty($users)) { $output = "No Users found."; } else { $output = count($users); } return $output;
/* totalUsers snippet */ return $modx->getCount('modUser');
return $modx->getCount('modUser', array('active' => '1'));
[[totalUsers]]
This might be a little faster and more efficient, since getCollection() will actually retrieve every user's data even though you don't need it.
If you want a count of all users active or not, you can do it with a single line, since there will always be at least one user (the admin):
<p>There are [[!totalUsers]] total users on this site</p>
/* totalUsers snippet */ return $modx->getCount('modUser');
If you only want active users it would be:
return $modx->getCount('modUser', array('active' => '1'));
This has nothing to do with getResources and I would put it in the page Template.
Unless it's critical that it be up-to-date, I would call it cached since that would give you faster page loads and it would be updated every time the cache is cleared (which happens whenever a page or element is saved).
[[totalUsers]]