坚决贯彻落实《网络信息内容生态治理规定》内容,共同营造清朗的网络环境!

  • 我们目前有6,411个页面,765个用户,18,556次编辑。
  • 欢迎加入火器百科注册一个账号,一起参与编写吧!
  • 如果编辑遇到不懂的问题可以点击帮助或者加入火器百科QQ群:欢迎加入火器百科官方群,群聊号码 766652219
  • 首页是Hio的三次修改版,沿用了各代首页。赞美吧!

模块:If empty

来自火器百科
Jimmyshjj留言 | 贡献2019年2月14日 (四) 11:21的版本 (https://zh.wikipedia.org/w/index.php?title=%E6%A8%A1%E5%9D%97:If_empty&oldid=50321970)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转到导航 跳转到搜索

可在Module:If empty/doc创建此模块的帮助文档

local p = {}

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:If empty', removeBlanks = false})

	-- For backwards compatibility reasons, the first 8 parameters can be unset instead of being blank,
	-- even though there's really no legitimate use case for this. At some point, this will be removed.
	local lowestNil = math.huge
	for i = 8,1,-1 do
		if args[i] == nil then
			args[i] = ''
			lowestNil = i
		end
	end

	for k,v in ipairs(args) do
		if v ~= '' then
			if lowestNil < k then
				-- If any uses of this template depend on the behavior above, add them to a tracking category.
				-- This is a rather fragile, convoluted, hacky way to do it, but it ensures that this module's output won't be modified
				-- by it.
				frame:extensionTag('ref', '[[Category:Instances of Template:If_empty missing arguments]]', {group = 'TrackingCategory'})
				frame:extensionTag('references', '', {group = 'TrackingCategory'})
			end
			return v
		end
	end
end

return p