Template:Categorize: Difference between revisions

From HorizonXI Wiki
m (added chatgpt interpreted documentation on template behavior)
m (added option to disable documentation and categorization simultaneously)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>{{#switch:{{lc:{{{1|}}}}}|no categories|no cat|nc = |#default = {{#ifeq:{{NAMESPACE}}||{{{2|}}}}}}}</includeonly><!--
<includeonly><onlyinclude>{{#switch:{{lc:{{{1|}}}}}|no categories|no cat|ndnc|ncnd|nc = |#default = {{#switch:{{NAMESPACE}}||Category={{{2|}}}}}<!--
-->}}</onlyinclude></includeonly>
==Usage==
*First unnamed parameter: set to ''nc'', ''no cat'' or ''no categories'' to force the template to do nothing. ''ndnc'' or ''ncnd'' will also work, intended with [[Template:Preview Only Infobox]] to disable categorization and documentation at the same time.
*Second unnamed parameter: put whatever is supposed to happen if the first parameter is not set to one of the above.
*Note: The template will also do nothing if the page has a namespace other than the main namespace or the namespace "Category". E.g. in the namespace "Template" it will do nothing.


--><noinclude>
The actual usage of the template is intended for categorization, as the name suggests. It allows to control categorization in other templates by forwarding the first unnamed parameter.


'''this documentation was generated by chatgpt's interpretation of the template code. Trust at your own responsibility.'''
Example:


== Template: Categorize ==
If a template "NPC" contains the line <pre>{{categorize|{{{1|}}}|[[Category:NPC]]}}</pre>
The "Categorize" template allows you to conditionally hide or suppress the output based on the value of the first parameter and the current namespace.
Then a call like
<pre>
{{NPC|nc
...
}}
</pre>
will put the ''nc'' into the categorize template and cause it to do nothing.  


=== Usage ===
A call like
<nowiki>{{Categorize|parameter|fallback}}</nowiki>
<pre>
{{NPC
...
}}
</pre>
without specifying the first unnamed parameter in a way that Template:categorize processes it will make Template:categorize do whatever is in its second unnamed argument. In this example, this is apply <nowiki>[[Category:NPC]]</nowiki>.


- '''parameter''': The value you want to evaluate. If it matches specific cases, the output will be suppressed.
Designing templates in this way allows to control categorization at template call, e.g. for use on example pages.
- '''fallback''' (optional): The fallback value to display if the first parameter doesn't match any cases or is not provided.
 
=== Cases ===
- If the first parameter matches "no categories," "no cat," or "nc," the output will be suppressed.
- If the first parameter doesn't match any cases or is not provided, the output will depend on whether the template is used within a namespace or outside of any namespace, and it will be controlled by the fallback value.
 
=== Example ===
<nowiki>{{Categorize|no categories|This template is used outside a namespace.}}</nowiki>
 
If used in the main namespace, the output will be suppressed. If used in any other namespace, the output will be "This template is used outside a namespace."
 
For any other parameter values, the output will follow the same behavior based on the specified cases and fallback.
 
Please note: This template should be used for conditional output control when dealing with categories or namespace-related conditions.
 
</noinclude>

Latest revision as of 16:13, 5 August 2024

Usage

  • First unnamed parameter: set to nc, no cat or no categories to force the template to do nothing. ndnc or ncnd will also work, intended with Template:Preview Only Infobox to disable categorization and documentation at the same time.
  • Second unnamed parameter: put whatever is supposed to happen if the first parameter is not set to one of the above.
  • Note: The template will also do nothing if the page has a namespace other than the main namespace or the namespace "Category". E.g. in the namespace "Template" it will do nothing.

The actual usage of the template is intended for categorization, as the name suggests. It allows to control categorization in other templates by forwarding the first unnamed parameter.

Example:

If a template "NPC" contains the line

{{categorize|{{{1|}}}|[[Category:NPC]]}}

Then a call like

{{NPC|nc
...
}}

will put the nc into the categorize template and cause it to do nothing.

A call like

{{NPC
...
}}

without specifying the first unnamed parameter in a way that Template:categorize processes it will make Template:categorize do whatever is in its second unnamed argument. In this example, this is apply [[Category:NPC]].

Designing templates in this way allows to control categorization at template call, e.g. for use on example pages.