Skip to content

Instantly share code, notes, and snippets.

@goldsky
Created December 24, 2013 08:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldsky/8110511 to your computer and use it in GitHub Desktop.
Save goldsky/8110511 to your computer and use it in GitHub Desktop.
Count how many resources which have specified TV that has specified value
<?php
$name = $modx->getOption('name', $scriptProperties);
$value = $modx->getOption('value', $scriptProperties);
if (empty($tvName) || empty($value)) {
return;
}
$tvObj = $modx->getObject('modTemplateVar', array(
'name' => $name
));
if (!$tvObj) {
return;
}
$tv2Res = $tvObj->getMany('TemplateVarResources', array(
'value:LIKE' => "%$value%"
));
return count($tv2Res);
@goldsky
Copy link
Author

goldsky commented Dec 24, 2013

[[tvCounter? &name=product-category &value=accessories]]

@adamwintle
Copy link

Unfortunately I can't get this working - how have you setup your TV?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment