Template:If in category
From TechInfoDepot
Jump to navigationJump to search
| This template is used on many pages, and changes to it will be widely noticed. Please test any changes in the template's /sandbox or /testcases subpages, or in a user subpage, and consider discussing changes at the talk page before implementing them. |
| Uses Lua: |
This template checks if a page is in a given category. The syntax is:
{{If in category|category name|output if the page is in the category|output if the page is NOT in the category|page=page name to test}}
Usage notes
- If no
|page=parameter is supplied, it defaults to the current page - The category name parameter treats Foo and Category:Foo as equivalent
- If neither output parameter is specified, it outputs yes if true and the empty string if false
Examples
Template:A note This page is in Category:X1.
{{If in category|page=Amastra subsoror|Extinct gastropods|Dead as the dodo|Perhaps it's still alive}}→ Lua error in Module:If_in_category at line 11: bad argument #1 to 'inArray' (table expected, got nil).{{If in category|page=Amastra subsoror|Category:Extinct gastropods|Dead as the dodo|Perhaps it's still alive}}→ Lua error in Module:If_in_category at line 11: bad argument #1 to 'inArray' (table expected, got nil).{{If in category|page=Amastra subsoror|Extinct gastropods}}→ Lua error in Module:If_in_category at line 11: bad argument #1 to 'inArray' (table expected, got nil).{{If in category|X1}}→ Lua error in Module:If_in_category at line 11: bad argument #1 to 'inArray' (table expected, got nil).{{If in category|X2}}→ Lua error in Module:If_in_category at line 11: bad argument #1 to 'inArray' (table expected, got nil).
TemplateData
This is the TemplateData for this template, which is used by TemplateWizard, the VisualEditor and still other tools.
TemplateData for If in category
Checks whether a page is in a category, and returns different output based on the answer.
| Parameter | Description | Type | Status | |
|---|---|---|---|---|
| Category | 1 | Category being checked to see if the page is in it; "Category:" prefix is optional
| Page name | required |
| If yes | 2 | Output if the page is in the category. If neither "If yes" nor "If no" are set, defaults to "yes". | Content | suggested |
| If no | 3 | Output if the page is not in the category | Content | suggested |
| Page | page | Page being checked. Defaults to the current page.
| Page name | optional |
| The above documentation is transcluded from Template:If in category/doc. (edit | history) Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages. Please add categories to the /doc subpage. Subpages of this template. |