Jump to content

Module:If in category

From Humanipedia
Revision as of 14:00, 6 September 2024 by hp>MusikBot II (Protected "Module:If in category": High-risk template or module: 32537 transclusions (more info) ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Lua error in package.lua at line 80: module 'Module:Yesno' not found. Script error: No such module "High-use". Template:Expensive This module implements {{if in category}}

Usage

<syntaxhighlight lang="wikitext" inline>Template:If in category</syntaxhighlight>

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 = {}
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)
	-- create a title object
	local page =  mw.title.new((args.page or '')) or mw.title.getCurrentTitle()
	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