Modul:HasValue: Unterschied zwischen den Versionen

Aus Stadtsprachen
Wechseln zu:Navigation, Suche
(Die Seite wurde neu angelegt: „local p = {} -- Function to check if at least one parameter has a value function p.hasAny(frame) local args = frame.args -- Check each argument for key, value in pairs(args) do -- Check if the value is not nil, not empty string, and not just whitespace if value and value ~= '' and mw.text.trim(value) ~= '' then return 'true' end end -- If no non-empty values found, return empty string (fal…“)
 
Keine Bearbeitungszusammenfassung
 
Zeile 9: Zeile 9:
         -- Check if the value is not nil, not empty string, and not just whitespace
         -- Check if the value is not nil, not empty string, and not just whitespace
         if value and value ~= '' and mw.text.trim(value) ~= '' then
         if value and value ~= '' and mw.text.trim(value) ~= '' then
             return 'true'
             return 1
         end
         end
     end
     end
      
      
     -- If no non-empty values found, return empty string (falsy in MediaWiki)
     -- If no non-empty values found, return empty string (falsy in MediaWiki)
     return ''
     return 0
end
end


Zeile 26: Zeile 26:
         -- Check if the value is not nil, not empty string, and not just whitespace
         -- Check if the value is not nil, not empty string, and not just whitespace
         if value and value ~= '' and mw.text.trim(value) ~= '' then
         if value and value ~= '' and mw.text.trim(value) ~= '' then
             return 'true'
             return 1
         end
         end
     end
     end
      
      
     -- If no non-empty values found, return empty string (falsy in MediaWiki)
     -- If no non-empty values found, return empty string (falsy in MediaWiki)
     return ''
     return 0
end
end


Zeile 56: Zeile 56:
         local value = templateArgs[paramName]
         local value = templateArgs[paramName]
         if value and value ~= '' and mw.text.trim(value) ~= '' then
         if value and value ~= '' and mw.text.trim(value) ~= '' then
             return 'true'
             return 1
         end
         end
     end
     end
      
      
     return ''
     return 0
end
end


return p
return p

Aktuelle Version vom 15. September 2025, 15:30 Uhr

Die Dokumentation für dieses Modul kann unter Modul:HasValue/Doku erstellt werden

local p = {}

-- Function to check if at least one parameter has a value
function p.hasAny(frame)
    local args = frame.args
    
    -- Check each argument
    for key, value in pairs(args) do
        -- Check if the value is not nil, not empty string, and not just whitespace
        if value and value ~= '' and mw.text.trim(value) ~= '' then
            return 1
        end
    end
    
    -- If no non-empty values found, return empty string (falsy in MediaWiki)
    return 0
end

-- Alternative function that accepts template parameters directly
function p.hasAnyTemplate(frame)
    local parentFrame = frame:getParent()
    local args = parentFrame.args
    
    -- Check each argument
    for key, value in pairs(args) do
        -- Check if the value is not nil, not empty string, and not just whitespace
        if value and value ~= '' and mw.text.trim(value) ~= '' then
            return 1
        end
    end
    
    -- If no non-empty values found, return empty string (falsy in MediaWiki)
    return 0
end

-- Function to check specific named parameters
function p.hasAnyNamed(frame)
    local args = frame.args
    local paramNames = {}
    
    -- Get the parameter names from the arguments
    for i = 1, 20 do  -- Support up to 20 parameters
        if args[i] then
            table.insert(paramNames, args[i])
        else
            break
        end
    end
    
    -- Get parent frame to access template parameters
    local parentFrame = frame:getParent()
    local templateArgs = parentFrame.args
    
    -- Check each named parameter
    for _, paramName in ipairs(paramNames) do
        local value = templateArgs[paramName]
        if value and value ~= '' and mw.text.trim(value) ~= '' then
            return 1
        end
    end
    
    return 0
end

return p