Answer the question
In order to leave comments, you need to log in
How to display the sum of the TV variable of child elements in MODx Revo?
Please help with an article or a link to the plugin - I've looked all over and can't find it.
I have no knowledge in php (only at the level of form handlers). I need to display in MODx the sum of all values of a variable of child elements.
In general, here is the link hm.newway.site/keyjsyi.html
there there are values like everything done by projects, for the amount, etc. - I want to make sure that these values are calculated automatically.
Answer the question
In order to leave comments, you need to log in
Here is a primitive snippet. Call it whatever you want and call it in the right place on the page.
Just replace parent => 10 with the id of the container for which you want to calculate the amount, and num with the name of the TV you want to calculate.
$count = 0;
$pdo = $modx->getService('pdoFetch');
$resources = $pdo->getCollection('modResource', array('parent' => 10), array('includeTVs' => 'num'));
foreach ($resources as $res) {
$count = $count + $res['num']
}
return $count;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question