Blog Sections Open
Tracking Resource Views with a TV and Plugin in Evolution CMS
A classic page-hit counter pattern for Evolution CMS using a text TV, an OnLoadWebDocument plugin, and optional listing integration.
Before analytics dashboards became the default answer for everything, many projects just needed one simple number: how many times was this resource viewed?
This older solution used a TV named hits and a plugin bound to OnLoadWebDocument. The plugin incremented the stored value and exposed the latest number through a placeholder.
Core plugin idea
$idtv = '12';
$id = $modx->resource->get('id');
$prosmotr = 0;
$tvs = $modx->getObject('modTemplateVarResource', array(
'tmplvarid' => $idtv,
'contentid' => $id
));
if ($tvs) {
$prosmotr = $tvs->get('value');
$prosmotr++;
$tvs->set('value', $prosmotr);
$tvs->save();
}
if ($prosmotr == 0) {
$prosmotr = 1;
$tv = $modx->newObject('modTemplateVarResource');
$tv->set('tmplvarid', $idtv);
$tv->set('contentid', $id);
$tv->set('value', $prosmotr);
$tv->save();
}
$modx->setPlaceholder('hitss', $prosmotr);
Rendering options
for a direct TV valuein resource listings with&includeTVs=`1`for uncached output in cached pages
This approach is simple, transparent, and still useful when you need a lightweight internal popularity signal without a heavier analytics dependency.
Reading URL Query Parameters with JavaScript
A small JavaScript helper for extracting query-string values when frontend behavior depends on GET parameters.
Ordering Sidebar Chunks with a Custom TV in Evolution CMS
A flexible sidebar pattern that lets editors choose the order of chunk-based blocks with a custom TV and a small helper snippet.