Jump to content
šŸ—³ļøšŸ–„ļø The Wikimedia Foundation December 2024 Developer Satisfaction Survey closes on the 2025-01-03. This survey helps us measure developer satisfaction, and prioritize work on tools and platforms for our technical contributors.

Module:Foreach

From wikiNonStop
Revision as of 07:01, 27 December 2024 by Majestix (talk | contribs) (1 revision imported: Initial )
(diff) ā† Older revision | Latest revision (diff) | Newer revision ā†’ (diff)
Module documentation

See Template:Fe.

See also Q15213889 (Q15213889) and specifically w:Module:For loop.

-- Replace http://www.mediawiki.org/wiki/Template: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 = {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 = {v}} end
    end
    return r
end

 
return p