Module:Foreach

-- Replace http://www.mediawiki.org/wiki/Template:Foreach

local p = {}

function p.w(frame) -- to be called from wikitext -- example:

local tplname = frame.args[1] local delim = frame.args[2] or nil r = '' for n,v in frame:argumentPairs do      if n > 3 and delim then r = r .. delim end if n>2 then r = r .. frame:expandTemplate{title = tplname, args = {v}} end end return r end

function p.m(t,frame) -- to be called from a module -- at the top: p={foreach = require "Module:foreach"} -- example: p.foreach.m({tplname,', ',item1,item3,item3},frame)

r = '' for n,v in ipairs(t) do      if n > 3 and delim then r = r .. delim end if n>2 then r = r .. frame:expandTemplate{title = tplname, args = {v}} end end return r end

return p