Module:IfEmpty: Difference between revisions
Jump to navigation
Jump to search
(Created page with "local p = {} function p.main(frame) local args = require('Module:Arguments').getArgs(frame, { wrappers = 'Template:If empty', removeBlanks = false }) for k,v in ipairs(args) do if v ~= '' then return v end end end return p") |
No edit summary |
||
(10 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local getArgs = require('Module:Arguments').getArgs | |||
local p = {} | local p = {} | ||
function p.main(frame) | function p.main(frame) | ||
-- Important to use removeBlanks = false here, because otherwise a blank | |||
wrappers = 'Template: | -- positional arg will be turned into nil, and Lua's ipairs() stops when a | ||
removeBlanks = false | -- value is nil, so you won't be able to iterate over the rest of the | ||
-- positional args. | |||
local args = getArgs(frame, { | |||
wrappers = 'Template:IfEmpty', | |||
removeBlanks = false, | |||
}) | }) | ||
for i, v in ipairs(args) do | |||
for | |||
if v ~= '' then | if v ~= '' then | ||
return v | return v | ||
end | end | ||
end | end | ||
end | end | ||
return p | return p |
Latest revision as of 00:12, 29 November 2023
This module implements the functionality of Template:IfEmpty. It returns the first template argument that's not empty or whitespace-only.
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.main(frame)
-- Important to use removeBlanks = false here, because otherwise a blank
-- positional arg will be turned into nil, and Lua's ipairs() stops when a
-- value is nil, so you won't be able to iterate over the rest of the
-- positional args.
local args = getArgs(frame, {
wrappers = 'Template:IfEmpty',
removeBlanks = false,
})
for i, v in ipairs(args) do
if v ~= '' then
return v
end
end
end
return p