มอดูล:Infobox

จาก Roleplay Wiki
รุ่นแก้ไขเมื่อ 21:58, 29 ตุลาคม 2569 โดย Khwankct (คุย | ส่วนร่วม) (แก้ชนิดข้อมูลพารามิเตอร์ของเฟรม)
ไปยังการนำทาง ไปยังการค้นหา

เอกสารการใช้งานสำหรับมอดูลนี้อาจสร้างขึ้นที่ มอดูล:Infobox/doc

local p = {}
local function val(a,k)
  local x = a and a[k]
  if x == nil then return '' end
  return mw.text.trim(tostring(x))
end
function p.infoboxTemplate(frame)
  local a = frame.args or ((frame.getParent and frame:getParent().args) or {})
  local root = mw.html.create('table'):addClass('infobox')
  local title = val(a,'honorific-prefix') .. val(a,'name')
  local suffix = val(a,'honorific-suffix'); if suffix ~= '' then title = title .. ' ' .. suffix end
  if title ~= '' then root:tag('caption'):addClass('infobox-title'):wikitext(title):done() end
  local image=val(a,'image'); if image ~= '' then local row=root:tag('tr'); row:tag('td'):attr('colspan','2'):css('text-align','center'):wikitext('[[ไฟล์:'..image..'|กลาง|'..(val(a,'image_size')~='' and val(a,'image_size') or (val(a,'imagesize')~='' and val(a,'imagesize') or '220px'))..']]'):done(); row:done() end
  local caption=val(a,'caption'); if caption ~= '' then local row=root:tag('tr'); row:tag('td'):attr('colspan','2'):css('text-align','center'):wikitext(caption):done(); row:done() end
  local keys={'order','monarch','term_start','term_end','predecessor','successor','birth_date','birth_place','party','spouse','alma_mater','religion'}
  for _,k in ipairs(keys) do local x=val(a,k); if x ~= '' then local row=root:tag('tr'); row:tag('th'):wikitext(k):done(); row:tag('td'):wikitext(x):done(); row:done() end end
  for i=1,20 do local office=val(a,'office'..i); if office ~= '' then local row=root:tag('tr'); row:tag('th'):wikitext(office):done(); local dates=val(a,'term_start'..i); local e=val(a,'term_end'..i); if e~='' then dates=dates..'<br>'..e end; row:tag('td'):wikitext(dates):done(); row:done() end end
  return tostring(root)
end
p.infobox=p.infoboxTemplate
return p