Difference between revisions of "Module:Foreach"
Jump to navigation
Jump to search
Rixithechao (talk | contribs) (Created page with "-- Replace http://www.mediawiki.org/wiki/Template:Foreach local p = {} function p.w(frame) -- called from Template:Fe local pframe = frame:getParent() local tplnam...") |
Rixithechao (talk | contribs) m |
||
Line 1: | Line 1: | ||
-- | -- Modified from https://www.mediawiki.org/wiki/Module:Foreach | ||
local p = {} | local p = {} | ||
Line 13: | Line 13: | ||
for n,v in ipairs(pframe.args) do | for n,v in ipairs(pframe.args) do | ||
if n > 3 then | if n > 3 then | ||
r = r .. delim | |||
end | |||
if n>2 then r = r .. frame:expandTemplate{title = tplname, args = {v}} end | if n > 2 then | ||
r = r .. frame:expandTemplate{title = tplname, args = {i=n-2, [1]=v}} | |||
end | |||
end | end | ||
return r | return r | ||
Line 32: | Line 34: | ||
r = r .. delim | r = r .. delim | ||
end | end | ||
if n>2 then r = r .. frame:expandTemplate{title = tplname, args = {v}} end | if n>2 then r = r .. frame:expandTemplate{title = tplname, args = {i=n-2, [1]=v}} end | ||
end | end | ||
return r | return r |
Revision as of 21:29, 16 June 2021
Documentation for this module may be created at Module:Foreach/doc
-- Modified from https://www.mediawiki.org/wiki/Module:Foreach local p = {} function p.w(frame) -- called from Template:Fe local pframe = frame:getParent() local tplname = pframe.args[1] local delim = pframe.args[2] r = '' for n,v in ipairs(pframe.args) do if n > 3 then r = r .. delim end if n > 2 then r = r .. frame:expandTemplate{title = tplname, args = {i=n-2, [1]=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 = '' tplname=t[1] delim=t[2] for n,v in ipairs(t) do if n > 3 then r = r .. delim end if n>2 then r = r .. frame:expandTemplate{title = tplname, args = {i=n-2, [1]=v}} end end return r end return p