[pmwiki-users] How to list all PageTextVariables?
Hans
design5 at softflow.co.uk
Tue Jul 22 12:09:35 CDT 2008
Monday, July 21, 2008, 10:54:21 PM, vincent at vizway.se wrote:
> Is there a way to get a list of page text variables
the following Markup expression definition may get you some of the
way you want:
# show all ptvs as name: value; input argument: PageName or list of page names
$MarkupExpr['allptvs'] = 'MXDisplayAllPTVs($pagename, $args[0])';
function MXDisplayAllPTVs($pagename, $list) {
global $PCache;
$pgout = array(); $out = array();
$plist = (isset($list)) ? explode(',',$list) : array($pagename);
foreach($plist as $pn) {
$pn = MakePageName($pagename, $pn);
$pgout[$pn][0] = "!!!![[$pn]]\n";
PageTextVar($pn, '');
foreach($PCache[$pn] as $key => $val) {
if (substr($key,0,3)!="=p_") continue;
$pgout[$pn][] = "'''".substr($key,3)."''': ".$val."\\\\\n";
}
if (!isset($pgout[$pn][1])) {
unset($pgout[$pn]);
continue;
}
sort($pgout[$pn]);
$out[] = implode("\n",$pgout[$pn]);
}
return implode("\n",$out);
}
Then use in a page like
{(allptvs0} - displays all ptvs of the same page
{(allptvs PageName)} - displays all ptvs of page PageName
{(allptvs Page1,Page2,Page3)} - display all ptvs of Page1, all ptvs
of Page2, all ptvs of Page3. Use a list of pagenames, comma separated.
You can use (plist) or (pagelist) markup expressions from POwerTools
to generate csv page lists, for instance
{(allptvs (plist Test.*))} - show all ptvs of all pages in group Test.
Output is formatted like
!!!!Page1
'''ptv1''': value1
'''ptv2''': value2
etc.
Note there is no attempt made to defuse markup which may be present
as a ptv value, so there may be unforseen results.
If you want a pagelist showing pages with PTV 'name1', where the PTV
has to have some value, you can use pagelist markup like
(:pagelist $:name1=- :) (add other parameters as needed)
~Hans
More information about the pmwiki-users
mailing list