پودمان:AlborzInfoBox
ظاهر
توضیحات این پودمان میتواند در پودمان:AlborzInfoBox/توضیحات قرار گیرد.
local p = {}
local data = mw.loadData('Module:AlborzInfoBox/Data/Geography')
--------------------------------------------------------------------------------
-- Render
--------------------------------------------------------------------------------
local function render(args)
local layout = data.layouts[args["نوع"] or "city"]
if not layout then
layout = data.layouts.city
end
local root = mw.html.create("table")
:addClass("infobox")
:addClass("alborz-infobox")
--------------------------------------------------------------------------
-- Title
--------------------------------------------------------------------------
local title = args["نام"] or mw.title.getCurrentTitle().text
root:tag("tr")
:tag("th")
:attr("colspan","2")
:wikitext(title)
--------------------------------------------------------------------------
-- Image
--------------------------------------------------------------------------
if args["تصویر"] and args["تصویر"] ~= "" then
root:tag("tr")
:tag("td")
:attr("colspan","2")
:wikitext("[[پرونده:" .. args["تصویر"] .. "|250px]]")
if args["توضیح تصویر"] and args["توضیح تصویر"] ~= "" then
root:tag("tr")
:tag("td")
:attr("colspan","2")
:wikitext(args["توضیح تصویر"])
end
end
--------------------------------------------------------------------------
-- Rows (FIXED PART)
--------------------------------------------------------------------------
for i = 1, #layout do
local key = layout[i]
local field = data.fields[key]
if field then
local value = nil
-- 🔴 FIX اصلی اینجاست:
if field.arg then
value = args[field.arg]
end
-- fallback مهم (برای جلوگیری از خالی شدن دادهها)
if (not value or value == "") and field.label then
value = args[field.label]
end
if value and value ~= "" then
local tr = root:tag("tr")
tr:tag("th")
:wikitext(field.label)
tr:tag("td")
:wikitext(value)
end
end
end
return tostring(root)
end
--------------------------------------------------------------------------------
-- Main
--------------------------------------------------------------------------------
function p.main(frame)
local args = {}
local parent = frame:getParent() or frame
for k, v in pairs(parent.args or {}) do
if v and v ~= "" then
args[k] = mw.text.trim(v)
end
end
for k, v in pairs(frame.args or {}) do
if v and v ~= "" then
args[k] = mw.text.trim(v)
end
end
return render(args)
end
return p