Template:Category handler/doc: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Ganaram inukshuk (talk | contribs)
doc
Ganaram inukshuk (talk | contribs)
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{dochead}}
{{dochead|header=metatemplate}}
{{Template rating|details=Currently in-progress and used for one other template. Category input may be adjusted.}}
{{Template rating|rating=ready|details=Functionally complete. See its corresponding module for more details.}}
{{clear}}
{{clear}}
{{lua}}
'''Template:Category handler''' is intended as a metatemplate that helps templates categorize pages. It also suppresses categories depending on the namespace or subpage.
'''Template:Category handler''' is intended as a metatemplate that helps templates categorize pages. It also suppresses categories depending on the namespace or subpage.


== Usage ==
=== Usage ===


Categories are entered as unnamed parameters, as shown.
Categories are entered as unnamed parameters, as shown.
Line 23: Line 22:
: <code><nowiki>{{Category handler | Abstract MOS patterns | 8-tone scales | debug=1 }}</nowiki></code>
: <code><nowiki>{{Category handler | Abstract MOS patterns | 8-tone scales | debug=1 }}</nowiki></code>


disables categories. Typical use as part of another template should instead use something like <code><nowiki>debug={{{debug|}}}</nowiki></code>, so that <code><nowiki>debug=1</nowiki></code> can be added to an instance of that template.
disables categories.


=== Category suppression ===
Typically, this template is used as part of another template, so use something like <code><nowiki>debug={{{debug|}}}</nowiki></code>, so that <code><nowiki>debug=1</nowiki></code> can be added to an instance of that template.


By default, this metatemplate allows categories within the following namespaces: main, file, mediawiki, template, category, and module. Templates placed those namespaces will not categorize those pages.
=== Category suppression rules and use-cases ===


Additionally, this metatemplate suppresses categories if the page has the following suffixes (subpages): doc or sandbox. This prevents templates from categorizing test or documentation pages, but not if the /doc page is transcluded. This means categorizing templates that categorize other templates will the template's main page, but not their /doc subpages. However, if a categorizing template's documentation is demonstrating its own use, this isn't enough, so adding <code><nowiki>debug=1</nowiki></code> is required to keep categorizing templates from erroneously categorizing themselves.
By default, this metatemplate allows categories within the following namespaces: main, file, mediawiki, template, category, and module. Templates placed outside of those namespaces will not categorize those pages. Additionally, pages with the suffix /doc or /sandbox will not be categorized.


This metatemplate is meant primarily for templates used within those namespaces. Use of this metatemplate is not required for templates with basic categorizing rules, or templates meant to be placed within other namespaces such as the user namespace.
This metatemplate is meant primarily for templates used within those namespaces. Use of this metatemplate is not required for templates with basic categorizing rules, or templates meant to be placed within other namespaces, such as the user namespace. Additionally, specialized templates, such as those meant for categorizing /doc pages, are unable to work with this template.
 
=== Changing suppressed namespaces ===
 
This template can be adjusted to allow or disallow suppression in different namespaces. The example below allows a template to add categories a page within the user namespace, but not templates or modules. Namespaces are delimited using either newlines or semicolons.
 
<code><nowiki>{{category handler | allowed_ns = user | excluded_ns = template; module}}</nowiki></code>
 
=== Use-case: templates that categorize templates ===
 
Templates are sometimes added to template documentation, such as [[Template:Todo]], which categorizes that page under a specific todo-task. Typically, such templates are added to a template's /doc page to be transcluded onto that template's page, instead of within the <code><nowiki><noinclude></noinclude></nowiki></code> block of a template's page.
 
For example, adding <code><nowiki>{{Todo|inline=1|add documentation}}</nowiki></code> to a template's documentation adds that template to [[:Category:Todo:add documentation]], but a naïve implementation of that template will also categorize that template's /doc subpage.
 
<pre>
{{#if: {{{inline|}}} | {{Mbox
| type = notice
| icon = Icon-Todo.png
| text = '''Todo:''' {{#if: {{{1|}}}| {{{1}}} }}
{{#if: {{{comment|}}}}}
}}
}}
{{#if: {{{1|}}} | [[Category:Todo:{{trim|{{{1}}}}}]] | [[Category:Todo]] }}
</pre>
 
If placed on the /doc subpage for a template called SomeTemplate, the todo-category will contain these pages:
* Template:SomeTemplate (template page)
* Template:SomeTemplate/doc (template's documentation)
 
Since this template suppresses categories on /doc subpages, adding this template to Template:Todo prevents it from categorizing the documentation page, so only Template:SomeTemplate is categorized.
 
<pre>
{{#if: {{{inline|}}} | {{Mbox
| type = notice
| icon = Icon-Todo.png
| text = '''Todo:''' {{#if: {{{1|}}}| {{{1}}} }}
{{#if: {{{comment|}}}}}
}}
}}
{{category handler | {{#if: {{{1|}}} | Todo:{{trim|{{{1}}}}} | Todo }}}}
</pre>

Latest revision as of 10:04, 29 October 2025

This template is a metatemplate. It is used to build other templates and should not be used standalone, except for testing or simple usage. This template is implemented by the Lua module Module:Category handler.
This template invokes the following functions: category_handler from Category handler.
This documentation is for a ready template. This message indicates that a template is ready for use, or has recently been repaired. This message may be removed once this template has been used on several pages or once it is verified to work as intended.

Details: Functionally complete. See its corresponding module for more details.

Template:Category handler is intended as a metatemplate that helps templates categorize pages. It also suppresses categories depending on the namespace or subpage.

Usage

Categories are entered as unnamed parameters, as shown.

{{Category handler | cat 1 | cat 2 | cat 3 }}

For example, the code below

{{Category handler | Abstract MOS patterns | 8-tone scales}}

categorizes the page under the following categories.

[[Category:Abstract MOS patterns]][[Category:8-tone scales]]

For testing purposes, categories can be turned off by adding debug=1. Modifying the previous example

{{Category handler | Abstract MOS patterns | 8-tone scales | debug=1 }}

disables categories.

Typically, this template is used as part of another template, so use something like debug={{{debug|}}}, so that debug=1 can be added to an instance of that template.

Category suppression rules and use-cases

By default, this metatemplate allows categories within the following namespaces: main, file, mediawiki, template, category, and module. Templates placed outside of those namespaces will not categorize those pages. Additionally, pages with the suffix /doc or /sandbox will not be categorized.

This metatemplate is meant primarily for templates used within those namespaces. Use of this metatemplate is not required for templates with basic categorizing rules, or templates meant to be placed within other namespaces, such as the user namespace. Additionally, specialized templates, such as those meant for categorizing /doc pages, are unable to work with this template.

Changing suppressed namespaces

This template can be adjusted to allow or disallow suppression in different namespaces. The example below allows a template to add categories a page within the user namespace, but not templates or modules. Namespaces are delimited using either newlines or semicolons.

{{category handler | allowed_ns = user | excluded_ns = template; module}}

Use-case: templates that categorize templates

Templates are sometimes added to template documentation, such as Template:Todo, which categorizes that page under a specific todo-task. Typically, such templates are added to a template's /doc page to be transcluded onto that template's page, instead of within the <noinclude></noinclude> block of a template's page.

For example, adding {{Todo|inline=1|add documentation}} to a template's documentation adds that template to Category:Todo:add documentation, but a naïve implementation of that template will also categorize that template's /doc subpage.

{{#if: {{{inline|}}} | {{Mbox
| type = notice
| icon = Icon-Todo.png
| text = '''Todo:''' {{#if: {{{1|}}}| {{{1}}} }}
{{#if: {{{comment|}}}}}
}}
}}
{{#if: {{{1|}}} | [[Category:Todo:{{trim|{{{1}}}}}]] | [[Category:Todo]] }}

If placed on the /doc subpage for a template called SomeTemplate, the todo-category will contain these pages:

  • Template:SomeTemplate (template page)
  • Template:SomeTemplate/doc (template's documentation)

Since this template suppresses categories on /doc subpages, adding this template to Template:Todo prevents it from categorizing the documentation page, so only Template:SomeTemplate is categorized.

{{#if: {{{inline|}}} | {{Mbox
| type = notice
| icon = Icon-Todo.png
| text = '''Todo:''' {{#if: {{{1|}}}| {{{1}}} }}
{{#if: {{{comment|}}}}}
}}
}}
{{category handler | {{#if: {{{1|}}} | Todo:{{trim|{{{1}}}}} | Todo }}}}