Module:ItemPage
Documentation for this module may be created at Module:ItemPage/doc
local p = {}
-- Check if item has any sources
local function hasSources(itemName)
local sources = mw.ext.cargo.query('ItemSource', '_pageName', {
where = 'item="' .. itemName .. '"',
limit = 1
})
return sources and #sources > 0
end
-- Main display function
function p.display(frame)
local args = frame:getParent().args
local itemName = args.item or args[1] or mw.title.getCurrentTitle().text
local output = {}
-- Always output the infobox
table.insert(output, frame:preprocess('{{Infobox Item}}'))
-- Conditionally output Sources section
if hasSources(itemName) then
table.insert(output, '\n== Sources ==')
table.insert(output, frame:preprocess('{{ItemSources}}'))
end
-- Set the default form for this page
table.insert(output, frame:preprocess('{{#default_form:Item}}'))
return table.concat(output, '\n')
end
return p