Module:ItemSlot

Revision as of 05:00, 27 November 2025 by Cobblemon (talk | contribs) (Created page with "local p = {} function p.main(frame) local args = frame.args local filesParam = args[1] or "" local linkTarget = args[2] local tooltip = args[3] local output = {} -- Split by comma for filename in string.gmatch(filesParam, '([^,]+)') do filename = filename:gsub("^%s*(.-)%s*$", "%1") -- trim spaces if not filename:lower():match("%.png$") then filename = filename .. ".png" end local imgTag if linkTarget and linkTarget ~= "" then...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

function p.main(frame)
  local args = frame.args

  local filesParam = args[1] or ""
  local linkTarget = args[2]
  local tooltip = args[3]

  local output = {}

  -- Split by comma
  for filename in string.gmatch(filesParam, '([^,]+)') do
    filename = filename:gsub("^%s*(.-)%s*$", "%1") -- trim spaces

    if not filename:lower():match("%.png$") then
      filename = filename .. ".png"
    end

    local imgTag
    if linkTarget and linkTarget ~= "" then
      imgTag = string.format('[[File:%s|link=%s]]', filename, linkTarget)
    else
      imgTag = string.format('[[File:%s]]', filename)
    end
    table.insert(output, imgTag)
  end

  local tooltipText = tooltip or filesParam
  if tooltip then
    result = result .. '<span class="item-tooltip">' .. tooltipText .. '</span>'
  end

  return '<div class="item-slot">' .. result .. '</div>'
end

return p