Module:Infobox Player: Difference between revisions
Appearance
Created player infobox module  |
testing a system to dynamically add fields |
||
| Line 1: | Line 1: | ||
local infobox = require('Module:Infobox') | local infobox = require('Module:Infobox') | ||
local p = {} | local p = {} | ||
-- Turn "seasonjoined" into "Seasonjoined" (or tweak this to split words on underscores/camelCase) | |||
local function humanLabel(name) | |||
  return mw.ustring.upper(mw.ustring.sub(name,1,1)) .. mw.ustring.sub(name,2) | |||
end | |||
function p.infobox(frame) | function p.infobox(frame) | ||
  local args   = frame:getParent().args | |||
  local outArgs = { title = args.username } | |||
  local count  = 0 | |||
  for key, val in pairs(args) do | |||
    if key ~= 'username' and val and val ~= '' then | |||
      count = count + 1 | |||
      outArgs['label'..count] = humanLabel(key) | |||
      outArgs['data' ..count] = val | |||
    end | |||
  end | |||
  outArgs.rows = count | |||
  return infobox.infobox{ | |||
    getParent = function() return { args = outArgs } end | |||
  } | |||
end | end | ||
return p | return p | ||
Revision as of 15:28, 21 June 2025
Documentation for this module may be created at Module:Infobox Player/doc
local infobox = require('Module:Infobox')
local p = {}
-- Turn "seasonjoined" into "Seasonjoined" (or tweak this to split words on underscores/camelCase)
local function humanLabel(name)
return mw.ustring.upper(mw.ustring.sub(name,1,1)) .. mw.ustring.sub(name,2)
end
function p.infobox(frame)
local args = frame:getParent().args
local outArgs = { title = args.username }
local count = 0
for key, val in pairs(args) do
if key ~= 'username' and val and val ~= '' then
count = count + 1
outArgs['label'..count] = humanLabel(key)
outArgs['data' ..count] = val
end
end
outArgs.rows = count
return infobox.infobox{
getParent = function() return { args = outArgs } end
}
end
return p