Module:If in category

From Celestial Lance Universe Wiki
This is an old revision of this page, as edited by Cellan3 (talk | contribs) at 12:07, 24 March 2025 (Created page with "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..."). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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