We are actively looking for staff to help us build the wiki. If you are interested please join our Discord server and apply.

Module:InfoboxModuleTest

From Moonbounce Wiki
Revision as of 10:26, 29 June 2024 by Frkl (talk | contribs) (Testing)
Jump to navigation Jump to search

Documentation for this module may be created at Module:InfoboxModuleTest/doc

-- Module:InfoboxTestModule
local p = {}

function p.displayFoundIn(frame)
  local foundIn = frame.args[1]
  local items = mw.text.split(foundIn, ',')
  local result = ""

  -- if there are no items, add "Nothing" as a placeholder
  if #items == 0 then
    items = {"Nothing"}
  end

  for i, item in ipairs(items) do
    item = mw.text.trim(item)

    -- generate an image name from the item name by replacing spaces with underscores
    local imageName = string.gsub(item, " ", "_")
    
    if item == "Nothing" then
      imageName = "X"
    end

    -- construct the new format
    result = result .. '[[File:' .. imageName .. '.png|24px|link=]]  ' .. item

    -- add a separator if not the last item
    if i < #items then
      result = result .. ' '
    end
  end

  return result
end

return p