rankCount = rankCount + 1  
if u['goals'] < goalNumber then -- player belongs to rowspan for new number of goals
-- need to generate code for the previous rowspan (if there is one)
-- then start the counts and player list for the new one  
if playerCount == 1 then
firstplayerCell = '\n|' .. goalscorerString -- if first player in list just create cell and set goals
goalNumber = u['goals']
--rank = 1
rankCount = 0
else -- else generate previous rowspan
local rowSpan = rankCount
if playerCount > maxRank * 1.5 then
firstplayerCell = '\n||' .. rankCount .. " players"
playerCells = ""
rowSpan = 1
end
tableString = tableString .. '\n|-\n||' .. rank
--if rankCount > 1 then tableString = tableString .. "=" end -- adds equals when rank shared
tableString = tableString .. firstplayerCell
tableString = tableString .. '\n||' .. goalNumber
tableString = tableString .. playerCells  
rank = rank + rankCount
if rank > maxRank then break end -- limit list top ten or value in parameter
rankCount = 0
goalNumber = u['goals']
firstplayerCell = '\n|' .. goalscorerString -- set first player cell for next rowspan
playerCells = ""
end
else -- else another player with same number of goals
playerCells = playerCells .. '\n|-' .. '\n|' .. goalscorerString -- add to player cell list
end
end -- reached end of list of goalscorers  
if tableString ~= "" then
tableString = tableString .. "\n|}"
return tableString
else
return ("No goals matching requested criteria.")
end  
end
function p.outputGoalscorers(, og) -- output list of goalscorers
if g.args['table'] then return p.tabulateGoalscorers(, og) end -- optional table output  
local outputString = ""
if og == "OG" then end  
-- ==============output the lists of goalscorers by goal======================
local goalNumber = 1000
--local goalMinimum = tonumber(templateArgs['minimum']) or 0  
local listOpen = false -- flag for list started by template  
for j,u in pairs(g.goalscorers) do -- run through sorted list of selected goalscorers  
--if u['goals'] < goalMinimum then break end -- limit list to goals over a threshold (now handled in select goalscorers)  
if u['goals'] < goalNumber then -- start new list of new number of goals
if listOpen then -- if an open list, close last list
outputString = outputString .. p.closeList
listOpen = false -- redundant as will be set true again
end
goalNumber = u['goals']  
local goalString = " கோல்"
--if og == "OG" then
if goalNumber < 0 then
goalString = " சுய" .. goalString
end
if math.abs(u['goals']) ~= 1 then goalString = goalString .. "s" end  
outputString = outputString .. "\n**" .. math.abs(u['goals']) .. goalString .. "**" -- list caption  
outputString = outputString .. p.openList(,og) --start new list
listOpen = true
--goalNumber = u['goals']
end
-- is the player active still?
local playerActive = false
if data.active_countries then
for k,v in pairs(data.active_countries) do
if v == u['country'] then
playerActive = true
break;
end
end
end
local _,roundStatus = p.getNumberMatches
if roundStatus == "complete" then playerActive = false end -- overrides active_countries  
-- wikitext for bullet list
local goalscorerString = '\n*<span>' .. p.addLinkedIcon(, u['country']) -- linked flag icon
if playerActive and g.args['bold']~='no' then
goalscorerString = goalscorerString .. " <b>" .. u['player'] .. "</b>" -- bolded name
else
goalscorerString = goalscorerString .. " " .. u['player'] -- name
end
goalscorerString = goalscorerString .. u['comment'] .. '</span>' -- comment for o.g.  
outputString = outputString .. goalscorerString -- .. " " .. tostring(u['goals'])  
end -- reached end of list of goalscorers  
if outputString ~= "" then
outputString = outputString .. p.closeList  
return outputString
else
return ("No goals matching requested criteria.")
end
end  
-- output icon linked to national team page
function p.addLinkedIcon(, country)
local icon = data.templates['flag_icon_linked'] -- fbicon etc set in data module
local level = data.templates['youth_level'] or "" -- parameter for youth level, ie under-21
-- equivalent to
local flagVariant = ""
if data.templates.flagvar and data.templates.flagvar[country] then
flagVariant = data.templates.flagvar[country]
end
if level ~= "" then
return :expandTemplate{ title = icon , args = { level, country, flagVariant } }
else
return :expandTemplate{ title = icon , args = { country, flagVariant } } -- flag icon
end
end
-- formatting of list under each number of goals
function p.openList(,og)  
return mw.getCurrentFrame:extensionTag{
name = 'templatestyles', args = { src = 'Div col/styles.css' }
} .. '<div>' -- perhaps add "column-count:3;"" to limit max number of columns?
end
function p.closeList
return '</div>'
end
function p.firstToUpper(str)
return (str:gsub("^%l", string.upper))
end  
-- handles parameters bold, further, extra
function p.addAdditionHeaderText(text, dateUpdated)
if g.args['inlineref'] then
text = text .. g.args['inlineref']
end
if g.args['bold'] and g.args['bold']~='no' then
text = text .. " Players highlighted in **bold** are still active in the competition."
end
if g.args['further'] then
if text ~= "" then text = text .. " " end
text = text .. g.args['further']
end
if g.args['extra'] then
text = text .. "\n\n" .. g.args['extra']
end
return text
end
-- count number of goals for data in template
function p.countGoals(list, number, totalGoals)  
local split = mw.text.split( list, "\n", true ) -- split the list for number of goals scorers with N goals
local count = #split * math.abs(number) -- calculate number of goals (including own goals)
totalGoals = totalGoals + count  
--mw.addWarning( "Entry: " .. list .. "[" .. count .. "]")  
return totalGoals
end  
-- use data supplied by template  
--function p.list
function p.useTemplateData
--getArgs  
---  
---
local statNumber = g.args['goals'] or g.args['assists'] or 0
local matches = g.args['matches']
local statType = "goal"
if g.args['assists'] then statType = "assist" end
if g.args['clean sheets'] then statType = "clean sheet" end
local ongoing = g.args['ongoing']
local text1 = "There"
if g.args['lc'] then text1 = "there" end
local text2 = "were"
if ongoing then text2 = "have been" end
local updateString = ""
local averageString = ""
local goalPlural = "s" -- goal(s)
if g.args['goals'] and tonumber(g.args['goals']) == 1 then
goalPlural = ""
text2 = "was"
if ongoing then text2 = "has been" end
end
local matchPlural = "es" -- match(es)
if g.args['matches'] and tonumber(g.args['matches']) == 1 then matchPlural = "" end  
-- auto version: string.format(" in %d match%s, for an average of %."..precision.."g goal%s per match", matches, pluralMatches, average, pluralAverage)
if g.args['goals'] and g.args['matches'] then
local averageGoals = g.args['goals']/g.args['matches']
local avGoalPlural = "s"
if averageGoals == 1 then avGoalPlural = "" end
averageString = string.format(" in %d match%s, for an average of %.3g goal%s per match", g.args['matches'], matchPlural, averageGoals, avGoalPlural)
end
if g.args['updated'] and g.args['updated'] ~= "complete" then
updateString = "&nbsp;(as of " ..g.args['updated'] .. ")"
end
local sep = "."
if g.args['sep'] then sep = g.args['sep'] end
local text = ""
if g.args['goals'] then
text = string.format("%s %s %d %s%s scored%s",
text1, text2, statNumber, statType, goalPlural, averageString..updateString..sep)
end
text = p.addAdditionHeaderText(text) -- handles template parameters bold, further, extra  
--**30 **
<div>
}</div>|}}
local output = "\n"
local number = 30  
local totalGoals = 0  
while number > -4 do -- for the each goals/assists  
local entry = g.args[number .. ' goals'] or g.args[number .. ' goal']
or g.args[number .. ' assists'] or g.args[number .. ' assist']
or g.args[number .. ' clean sheets'] or g.args[number .. ' clean sheet']  
if number < 0 then
entry = g.args[math.abs(number) .. ' own goals'] or g.args[math.abs(number) .. ' own goal']
statType = "own goal"
end
local plural = "s"
if number == 1 or number == -1 then plural = "" end