Module:HeroData: Difference between revisionsGive feedback
m concept for get_hero_infobox |
m write_hero_infobox now actually evaluates the template Tags: Mobile edit Mobile web edit |
||
| Line 53: | Line 53: | ||
--{{#invoke:HeroData|write_hero_infobox|HERO_NAME}}-- | --{{#invoke:HeroData|write_hero_infobox|HERO_NAME}}-- | ||
p.write_hero_infobox = function(frame) | p.write_hero_infobox = function(frame) | ||
hero_name = frame.args[1] | |||
hero = get_json_item(hero_name) | |||
if(hero == nil) then return "Hero Not Found" end | |||
-- Prepare the arguments for the template | |||
local templateArgs = {} | |||
for stat_name, stat_value in pairs(hero) do | |||
if (type(stat_value) ~= "table") then -- skips complex nested tables | |||
templateArgs[stat_name] = stat_value | |||
end | |||
end | |||
-- Use expandTemplate to evaluate the Infobox_hero template | |||
local templateTitle = mw.title.new("Template:Infobox_hero") | |||
local expandedTemplate = mw.getCurrentFrame():expandTemplate{ title = templateTitle, args = templateArgs } | |||
return expandedTemplate | |||
end | end | ||