Module:TeamNav

local p = {} local cargo = mw.ext.cargo

local i18n = { navbox_name = 'TeamNav', article_teams = 'Professional teams', error_no_data = 'Cargo data unavailable', }

function p.main(frame) local navbox = { ['name'] = i18n.navbox_name, ['title'] = string.format('%s', i18n.article_teams), ['state'] = 'uncollapsed', ['bodyclass'] = 'hlist', } local cargo_regions = cargo.query('professional_teams', 'region',                                     { where='disbanded IS NULL', groupBy='region' }) assert(cargo_regions, i18n.error_no_data) for i,info in ipairs(cargo_regions) do   local cargo_teams = cargo.query('professional_teams', '_pageName, name, icon',                                    { where='disbanded IS NULL AND region="'.. info.region ..'"',                                    groupBy='_pageID' })

local teams = {} for _,team in ipairs(cargo_teams) do     -- Add the default icon if necessary if team.icon == '' then team.icon = 'Team icon Default.png' end local element = string.format('* %s ',                                    team.icon, team._pageName, team._pageName, team.name) table.insert(teams, element) end

navbox['group' .. i] = string.format('%s', i18n.article_teams, info.region, info.region) navbox['list' .. i] = table.concat(teams, '\n') end

return frame:expandTemplate{ title = 'Navbox', args = navbox } end

return p