Jump to content

Module:If in category: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
test
test
Line 17: Line 17:
end
end
if TableTools.inArray(page.categories, string.gsub( args[1], '^[Cc]ategory:', '' )) then
if TableTools.inArray(page.categories, string.gsub( args[1], '^[Cc]ategory:', '' )) then
if (not args[2]) and (not args[3]) then
if not args[3] then
-- if we are are not given anything to return, return 'yes' if it evalulates to true
-- if we are are not given anything to return, return 'yes' if it evalulates to true
return 'yes'
return args[2] or 'yes'
else
else
return args[2]
return args[2]

Revision as of 15:44, 5 September 2024

local p = {}
local TableTools = require('Module:TableTools')

function p.main(frame)
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	local page
	-- create a title object
	if args.page then
		page = mw.title.new(args.page)
	else
		page = mw.title.getCurrentTitle()
	end
	if TableTools.inArray(page.categories, string.gsub( args[1], '^[Cc]ategory:', '' )) then
		if not args[3] then
		-- if we are are not given anything to return, return 'yes' if it evalulates to true
    		return args[2] or 'yes'
    	else 
    		return args[2]
		end
	else
		return args[3]
	end
end

return p