Module:ItemData: Difference between revisions

LVL (talk | contribs)
Add get_builds_into functions to lookup which items use the current item as a component (reverses the Components array).
LVL (talk | contribs)
Fix get_builds_into to expand {{ItemIcon}} templates internally using expandTemplate so they render correctly inside #if conditionals instead of showing raw wikitext.
Line 506: Line 506:


-- Template: {{#invoke:ItemData|get_builds_into|ITEM_NAME}}
-- Template: {{#invoke:ItemData|get_builds_into|ITEM_NAME}}
-- Returns: {{ItemIcon|Parent1}}, {{ItemIcon|Parent2}}, and {{ItemIcon|Parent3}}
-- Returns fully rendered ItemIcon templates
p.get_builds_into = function(frame)
p.get_builds_into = function(frame)
local item = frame.args[1]
local item = frame.args[1]
Line 515: Line 515:
for _, key in ipairs(parents) do
for _, key in ipairs(parents) do
local name = data[key] and data[key]["Name"] or key
local name = data[key] and data[key]["Name"] or key
table.insert(parts, string.format("{{ItemIcon|%s}}", name))
local icon = mw.getCurrentFrame():expandTemplate{ title = "ItemIcon", args = { name } }
table.insert(parts, icon)
end
end