Module:AutoHeader: Difference between revisions
Appearance
Intcreator (talk | contribs) No edit summary |
Intcreator (talk | contribs) No edit summary Tag: Reverted |
||
Line 8: | Line 8: | ||
return frame:getParent():getTitle() | return frame:getParent():getTitle() | ||
end | end | ||
if(frame[getParent][getParent] ~= nil) then | if(frame[getParent] and frame[getParent][getParent] ~= nil) then | ||
return frame:getParent():getParent():getTitle() | return frame:getParent():getParent():getTitle() | ||
end | end |
Revision as of 20:12, 6 January 2025
Documentation for this module may be created at Module:AutoHeader/doc
local p = {}
p.getQuery = function(frame)
if(frame[getTitle] ~= nil) then
return frame:getTitle()
end
if(frame[getParent] ~= nil) then
return frame:getParent():getTitle()
end
if(frame[getParent] and frame[getParent][getParent] ~= nil) then
return frame:getParent():getParent():getTitle()
end
end
p.getData = function(frame)
-- local ret = mw.visualdata.query( schema ("inventory_item"), query (string), printouts (list or table), params (table) )
local result = mw.visualdata.query( 'Phone', p.getQuery(frame), {'manufacturer'}, {} )
-- local result = mw.visualdata.query( 'Phone', "Model 500", {'manufacturer'}, {} )
return result
end
p.getJson = function(frame)
-- local newObj = {}
-- for k in pairs(frame) do newObj[k] = "value" end
-- return mw.text.jsonEncode(newObj)
local data = p.getData(frame)
return mw.text.jsonEncode(data)
end
p.getIntroParagraph = function(frame)
local data = p.getData(frame)
-- for k in pairs(data) do return k end
-- local first = data[1]
-- return mw.text.jsonEncode(first)
-- local obj = data[1]
local obj = data
local title = obj.title
local manufacturer = obj.data.manufacturer
return string.format('The %s was manufactured by %s', title, manufacturer)
end
return p