Template:Collapsible option

Revision as of 20:12, 22 November 2026 by Desiminakh (talk | contribs) (Created page with "<includeonly>{{#if:{{{nohead|}}}||{{#switch:{{{headlevel|4}}}|2=== {{{heading|How to manage this template's initial visibility}}} ==|3==== {{{heading|How to manage this template's initial visibility}}} ===|#default===== {{{heading|How to manage this template's initial visibility}}} ====}}}} {{#if:{{{nobase|}}}||To set whether this template is shown open or closed when the page first loads, use the <code>|{{{statename|state}}}=</code> parameter:}} * <code>|{{{st...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A documentation helper for navigation boxes and other collapsible templates. Put it on a template's documentation page to explain the state parameter. It shows nothing in articles because it is only used on documentation pages.

Usage

On the documentation of, for example, Template:Rajasthan districts:

{{Collapsible option}}
{{Collapsible option|Rajasthan districts|default=collapsed}}

Parameters

Parameter Description
1 Template name used in the examples. Default: the current page name (without /doc).
default The state used when no parameter is given. Default: autocollapse.
statename Name of the parameter, if the template uses a different one (default state).
heading Custom heading text.
headlevel Heading level: 2, 3 or 4 (default).
nohead Any value = no heading.
nobase Any value = leave out the introductory sentence.
extra Extra text added at the end.

Example output

How to manage this template's initial visibility

To set whether this template is shown open or closed when the page first loads, use the |state= parameter:

  • |state=collapsed – the template starts closed, showing only its title bar. Example: {{Example navbox |state=collapsed}}
  • |state=expanded – the template starts open and fully visible. Example: {{Example navbox |state=expanded}}
  • |state=autocollapse – the template starts closed only if another collapsible box is on the same page. Example: {{Example navbox |state=autocollapse}}

If the parameter is not given, the template's default state is collapsed. Readers can always open or close the box with the show/hide link in its title bar.

Making a template collapsible

For the state parameter to work, the template's main table needs the mw-collapsible class, for example:

{| class="wikitable mw-collapsible {{#switch:{{{state|}}}|collapsed=mw-collapsed|expanded=|autocollapse=autocollapse|#default=autocollapse}}"
! Title
|-
| Content
|}
  • collapsed and expanded work with standard MediaWiki (class mw-collapsible, plus mw-collapsed to start closed).
  • autocollapse needs a small script in MediaWiki:Common.js that closes such boxes when there are two or more on the page. Without it, autocollapse boxes stay open.

Documentation helper that explains the state= parameter (collapsed/expanded/autocollapse) of a collapsible template.

Template parameters[Edit template data]

This template prefers block formatting of parameters.

ParameterDescriptionTypeStatus
Template name1

no description

Lineoptional
Default statedefault

no description

Suggested values
autocollapse collapsed expanded
Default
autocollapse
Lineoptional
Parameter namestatename

no description

Default
state
Lineoptional
Headingheading

no description

Lineoptional
Heading levelheadlevel

no description

Default
4
Numberoptional
No headingnohead

no description

Lineoptional
No introductionnobase

no description

Lineoptional
Extra textextra

no description

Contentoptional