[pmwiki-users] Fwd: pagelist of referenced items
Peter Bowers
pbowers at pobox.com
Sat Aug 14 03:28:36 CDT 2010
On Fri, Aug 13, 2010 at 5:15 PM, Markus Heinzer <keusen at gmail.com> wrote:
> Hello Peter
> I would be interested to do it the way you suggest, since with my actual
> solution I still have to create 200 pages by hand. And it seems to work but
> probably one could find an even nicer way of doing it.
>
> Actually in PHP-logic (the only programming language I know) I would do it
> (probably not the most elegant way...) like that:
>
> for ($topicarea = 1; $topicarea <= 5; $topicarea++)
> {
> for ($questionnumber = 1; $questionnumber <= 200; $questionnumber++)
> {
> echo 'topic area '.$topicarea.', question number '.$questionnumber.':
> ';
> (:pagelist "[[#answer-$topicarea-$questionnumber]]":)
> }
> }
Here's how that would look in WikiSh:
===(snip)===
{(wikish source {$FullName}#generate_page_list)}
(:if false:)
[[#generate_page_list]]
null --timeout:60
set i = 1
while test ${i} -le 5
do
set j = 1
while test ${j} -le 20
do
echo 'topic area ${i}, question number ${j}:\\'
echo '(:pagelist group=Test "[[#answer-${i}-${j}]]":)'
set j ++
done
set i ++
done
[[#generate_end]]
(:ifend:)
===(snip)===
It occurs to me that you could do something very similar with a markup
since you're familiar with PHP (code very lightly tested - use at your
own risk):
===(snip)===
Markup("loop-de-loop", "<pagelist", "/\\(::loop-de-loop (.*?)::\\)/e",
'NestedLoopEcho(\$pagename, "$1")');
function NestedLoopEcho($pagename, $arg)
{
$arg = stripslashes(str_replace('\n', "{newline}", $arg));
$opt = array('start1'=>1, 'end1'=>5, 'start2'=>1, 'end2'=>200);
$opt = array_merge($opt, ParseArgs($arg));
$rtn = "";
for ($i = $opt['start1']; $i <= $opt['end1']; $i++)
for ($j = $opt['start2']; $j <= $opt['end2']; $j++) {
if ($opt['fmt1']) $rtn .= str_replace(array('{loop1}',
'{loop2}', '{newline}'), array($i, $j, "\n"), $opt['fmt1']);
if ($opt['fmt2']) $rtn .= str_replace(array('{loop1}',
'{loop2}', '{newline}'), array($i, $j, "\n"), $opt['fmt2']);
}
return $rtn;
}
===(snip)===
then in your page you would "call it" like this:
===(snip)===
(::loop-de-loop end1=6 end2=10 fmt1="Topic {loop1} Question
{loop2}:\n\n" fmt2='(:pagelist "[[#answer-{loop1}-{loop2}]]":)\n\n'::)
===(snip)===
-Peter
More information about the pmwiki-users
mailing list