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: Difference between revisions

From Moonbounce Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 22: Line 22:
     end
     end


     result = result .. '[[File:' .. imageName .. '.png|24px|link=]]  [[' .. item .. ']]'
     result = result .. '[[File:' .. imageName .. '.png|24px|link=]]&nbsp;&nbsp;[[' .. item .. ']]<br />'
 
    -- add a separator if not the last item
    if i < #items then
      result = result .. ' '
    end
   end
   end



Revision as of 10:59, 29 June 2024

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

    result = result .. '[[File:' .. imageName .. '.png|24px|link=]]&nbsp;&nbsp;[[' .. item .. ']]<br />'
  end

  return result
end

return p