Module:If in category
Jump to navigation
Jump to search
This module implements {{if in category}}
Usage
{{if in category | [category] | [result if true] | [result if false] | page = [page] }}
If |page=
is omitted, the current page is used. If both the second and third unnamed parameters are omitted, the second unnamed parameter defaults to yes.
local p = {}
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
return p._main(args)
end
function p._main(args)
-- create a title object
local page = (args.page and mw.title.new(args.page)) or mw.title.getCurrentTitle()
if require('Module: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