Can this extension be used to loop through predetermined arrays to create a nicely formatted table? I want to be able to call a template (eg Journal), which defines two array-style parameters (stage and journal, with values being comma delimited [eg stage=0,10,20,30 and entry=test,test,test]) and generates a row for each (starting the row with
, with each iteration placing the next value from each into each ), but all I get are "maximum loops reached" and poorly created tables. Please assist, thanks.Topic on Extension talk:Loops
Use Extension:Scribunto instead of hacky extensions like this one.
@110.149.188.132: Alrighty, time for me to learn a new scripting language! Thanks.
Since the editing box is broken....
I looked into Scribunto, it looks quite complicated and I'm not very good with interpreter style languages like that. I understand it's "hacky", but if I could pull off what I want using just generic MediaWiki extensions like Loops and Arrays, I would appreciate any advice. :)
You can increase the maximum allowed loops, but it has a limit there for a reason. It would have pretty poor performance. Making a loop in lua is simple.
local p = {}
p.loop = function(frame)
local stage = frame.args.stage
local rows = {}
-- the actual looping part
for value in mw.text.gsplit(stage, ',') do
table.insert(rows, '|' .. value)
end
return ' {|\n' .. table.concat(rows, '\n|-\n') .. '\n|}'
end
return p
This outputs each value on a separate row. I'm not sure exactly what format of table you're looking for, but maybe you get the gist of it?
Making a loop in PhpTags is simpler for me :-)
It is the same:
$stage = explode( ',', $argv['stage'] );
$rows = [];
// the actual looping part
foreach( $stage as $value ) {
$rows[] = '|' . $value;
}
echo "\n{|\n" . implode( "\n|-\n", $rows ) . "\n|}";
Have more fun!
Thanks for the posts. @Pastakhov: Sorry, that won't work because this is for a Wikia wiki, so yeah....
@110.149.188.132: Thanks! I'll have a look at the code and see if I can piece it together.