[pmwiki-users] PAGELIST / Math / summatory

Eemeli Aro eemeli at gmail.com
Thu Sep 3 13:26:16 CDT 2009

2009/9/3 edwin marte <edwin.marte at leidba.com>:
> 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
> Any Ideas?

This is a bit tricky, but entirely possible using templated pagelists
and markup expressions.

The tricky part is due to markup expressions being handled before
pagelists, so you can't include a (:pagelist:) inside a {(markup
expression)}. However, after pagelists are generated their contents
are passed through the rendering again, so you can build a pagelist
template that'll produce a valid markup expression to do your variable
addition. The second tricky part comes from markup expressions needing
to be on a single line.

For the following to work, you'll need {(math)} from

First, the template needs to be defined somewhere:

[[#datasum]](:template first:){(math 0(:template
each:)+0{=$:DATA}(:template last:) )}

In case that's mangled in the mailing, the above needs to be on
exactly two rows, each started by '[[#datasum'. The extra 0's are
necessary for handling pages that don't have $:DATA set to some value.

And then you can use the following pagelist to get the sum:

(:pagelist fmt=#datasum group=SomeGroup:)

Alternatively, the MarkupExpresssionSamples page also has {(sum)},
with which the template should be:

[[#datasum]](:template first:){(sum (:template
each:){=$:DATA}(:template last:) )}


More information about the pmwiki-users mailing list