Module:Utilities: Difference between revisions

Jump to navigation Jump to search
LVL (talk | contribs)
Fix decimal point stripping
m Added expand_templates util to help optimise template expansions
Line 234: Line 234:
     end
     end
     return false
     return false
end
-- Expands multiple of the same template in a single preprocess call
function p.expand_templates(frame, template_name, args_array)
    local strings = {}
    for i, args in ipairs(args_array) do
        local parts = {"{{", template_name, "|"}
        for j, arg in ipairs(args) do
            if j > 1 then parts[#parts + 1] = "|" end
            parts[#parts + 1] = arg
        end
        parts[#parts + 1] = "}}"
        strings[i] = table.concat(parts)
    end
    local expanded = frame:preprocess(table.concat(strings, "\x01"))
    return mw.text.split(expanded, "\x01")
end
end


return p
return p