Documentation for this module may be created at Module:ModuleShowVariantsOrSingle/doc
------------------------------------ -- Modules can have variants, or they can be one of a kind. -- It doesn't make sense to show all the variant fluff if a module is one of a kind. -- This script shows or hides all that variant info based on how many unique modules are defined, -- no having to manually pick a template yourself! local p = {} local function moreThanOne(module_name) local variants_chapter = "== Variants ==\n{{Template:ModuleTableCompareLevels|module_name=" .. module_name .. "}}\n\n" local variant_details_chapter = "== Variant Details ==\n" return variants_chapter .. variant_details_chapter end local function addChapter(variantID, moduleText) return "\n= " .. tostring(variantID) .. " =\n" ..moduleText end local function getVariantFromArgs(frame, variantID) if variantID == 1 then return frame.args.variant1 elseif variantID == 2 then return frame.args.variant2 elseif variantID == 3 then return frame.args.variant3 elseif variantID == 4 then return frame.args.variant4 elseif variantID == 5 then return frame.args.variant5 elseif variantID == 6 then return frame.args.variant6 elseif variantID == 7 then return frame.args.variant7 elseif variantID == 8 then return frame.args.variant8 elseif variantID == 9 then return frame.args.variant9 elseif variantID == 10 then return frame.args.variant10 else return "ERROR: Module:ModuleShowVariantsOrSingle told to pass an unknown VariantID. Please tell us on Discord!" end end function p.processData(frame) if frame.args.count == nil then return "ERROR: Module:ModuleShowVariantsOrSingle not passed a count. Please tell us on Discord!" end local smw_count = tonumber(frame.args.count) -- Something like frame.args[i] won't work, manually pulling the values by name local variant = frame.args.variant1 local result = "" if smw_count > 1 then result = moreThanOne(frame.args.module_name) for i=1, smw_count do result = result .. addChapter(i, getVariantFromArgs(frame, i)) end result = result .. "\n<headertabs />" else result = getVariantFromArgs(frame, 1) end return frame:preprocess(result) end return p