Jump to content

Module:CountRows: Difference between revisions

From GaplaWiki
Created page with "local p = {} function p.count(frame) local args = frame:getParent().args local count = 0 for k, v in pairs(args) do if type(k) == "number" and v ~= "" and v ~= nil then count = count + 1 end end return count end return p"
 
No edit summary
 
Line 1: Line 1:
local p = {}
local p = {}


function p.count(frame)
function p.countpattern(frame)
     local args = frame:getParent().args
     local text = frame:getParent():getParent():getTitle() -- niepotrzebne, ale zostaw
    local templateContent = mw.title.new(frame.args[1]):getContent() -- pobiera treść szablonu
    local pattern = frame.args[2] or "data%-sort%-value"
   
    if not templateContent then return 0 end
   
     local count = 0
     local count = 0
     for k, v in pairs(args) do
     for _ in string.gmatch(templateContent, pattern) do
         if type(k) == "number" and v ~= "" and v ~= nil then
         count = count + 1
            count = count + 1
        end
     end
     end
     return count
     return count

Latest revision as of 20:06, 18 October 2026

Documentation for this module may be created at Module:CountRows/doc

local p = {}

function p.countpattern(frame)
    local text = frame:getParent():getParent():getTitle() -- niepotrzebne, ale zostaw
    local templateContent = mw.title.new(frame.args[1]):getContent() -- pobiera treść szablonu
    local pattern = frame.args[2] or "data%-sort%-value"
    
    if not templateContent then return 0 end
    
    local count = 0
    for _ in string.gmatch(templateContent, pattern) do
        count = count + 1
    end
    return count
end

return p