[pmwiki-users] PAGELIST / Math / summatory
Hans
design5 at softflow.co.uk
Thu Sep 3 14:47:26 CDT 2009
Thursday, September 3, 2009, 3:14:12 PM, edwin marte wrote:
> What I have is SomeGroup, wich have page1, page2, page3, etc. Every
> page have a page variable let's say called DATA.
> So if we have let's say:
> {SomeGroup.page1$:DATA} =10
> {SomeGroup.page2$:DATA} =20
> {SomeGroup.page3$:DATA} =15
> I want to be able to build a pagelist for giving me Total:45
Here is another approach, using markup expressions.
Add the following to config:
# sum of data ptvs listed as data= ;
# input argument PageName or csv list of pagenames
MarkupExpr['sumdata'] = 'MXSumDataPTVs($pagename, $args[0], $argp)';
function MXSumDataPTVs($pagename, $list, $args) {
$sum = '';
if(!isset($args['data'])) return 'no data PTVs selected';
$ptvs = explode(',',$args['data']);
$plist = (isset($list)) ? explode(',',$list) : array($pagename);
foreach($plist as $pn) {
$pn = MakePageName($pagename, $pn);
foreach ($ptvs as $d) {
$v = PageTextVar($pn, $d);
$sum += floatval($v);
}
}
return $sum;
}
install PowerTools to use pagelist or plist markup expressions
http://www.pmwiki.org/wiki/Cookbook/PowerTools
then use in your page something like this to show the sum
of PTVs named ABC and XYZ
{(sumdata (plist Test.Name*) data=ABC,XYZ)}
You need data= as parameter for the PTVs, you can use one or several
separated by comas.
The first argument is a page name or csv page list, which is supplied
in the example with markup expression (plist)
You could use a (pagelist ...) markup expression.
Or simply
{(sumdata Page1,Page2,Page3 data=DATA)}
to sum PTV 'DATA' from pages Page1, Page2 and Page3
I should add the (sumdata ) expression to PowerTools i think.
~Hans
More information about the pmwiki-users
mailing list