Module:If elseif

From Eurovision Wiki
Revision as of 09:02, 19 March 2026 by Alfie (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

p = {}

local yesno = require('Module:Yesno')

p['_elseif'] = function(args)
	local n = 1
	repeat
		local ifval, thenval
		if args[n] then
			if args[n+1] then
				ifval, thenval = args[n], args[n+1]
				n = n + 2
			else
				return args[n]
			end
		elseif args['if' .. n] and args['then' .. n] then
			ifval, thenval = args['if' .. n], args['then' .. n]
			n = n + 1
		else
			return args['else'] or ""
		end
		if yesno(args.yesno) then
			if yesno(ifval) then return thenval end
		elseif mw.text.trim(ifval or '') ~= '' then
			return thenval
		end
	until false
end

p['elseif'] = function(frame)
	local args = require('Module:Arguments').getArgs(frame, {trim = false, removeBlanks = false})
	return p['_elseif'](args)
end

p[''] = p['elseif']

return p