Template:Collapse/doc

Template page

The {{collapse|folding text}} template is used for placing collapse boxes around short discussions and bits of discussions. To fold long discussion threads, use {{Collapse top}}... lots of text ...{{Collapse bottom}}. There are cases where these template will not work. See Help:Collapsing for other options.

This template should only be used in accordance with the OODA WIKI:refactoring talk pages guideline; it should never be used to end a discussion over the objections of other editors, except in cases of unambiguous disruptive editing.

Do not hide content in articles. This violates the WP:Manual of Style#Scrolling lists and collapsible content and WP:Accessibility guidelines.

Usage

Note: {{Collapse}} needs to be substed in order for the time stamp functionality to work properly.

{{Collapse|1=Discussion text to be put into box.|2=Optional custom heading}}

It is definitely safest to use the named |1= and |2= parameters, because otherwise any "=" character will break the template.

For compatibility with various discussion-boxing and -closing, and discussion-wrapping templates, |1= can also be given as |content= or |text=, and |2= can also be given as |title=, |reason=, |header=, |heading=, or |result=.

This works with collapsed bulleted list (the first bullet will look correct):
{{Collapse|title=|Bulleted list}} Start bulleted list on a new line.

HTML version

If you find that the template does not function properly in a particular circumstance, this is most likely because the wikicode table markup ({|, etc.) only works when it is at the beginning of a newline.

A workaround for this is the "pure HTML" (‎<table>, etc.) variant of this template, {{Collapse/HTML}}, which is identical (same parameters, etc.) other than in not using wikimarkup for the layout-table code.

The bg parameter

The bg parameter is optional. It changes the background color. Use Web color values (e.g. #F0F2F5).

Example

{{Collapse|1=Discussion text to be put into box.|bg=#F0F2F5}} creates:

Extended content
Discussion text to be put into box.

The padding parameter

The padding parameter adjusts the amount of cell padding (defaults to 8px):

{{Collapse|1=Discussion text to be put into box.|padding=20px}} creates the following (expand the box to see the border padding effect):

Extended content
Discussion text to be put into box.

The float parameter

The float parameter allows the collapsed content to float to the left, right, or center of the page (defaults to none with width = 100%):

{{Collapse|1=Discussion text to be put into box.|float=center}} creates the following:

Extended content
Discussion text to be put into box.

{{Collapse|1=Discussion text to be put into box.|float=center|width=30em}} creates the following:

Extended content
Discussion text to be put into box.

{{Collapse|1=Discussion text to be put into box.|float=left|width=30em}} creates the following:

Extended content
Discussion text to be put into box.

{{Collapse|1=Discussion text to be put into box.|float=right|width=30em}} creates the following:

Extended content
Discussion text to be put into box.

{{Collapse|1=Discussion text to be put into box.|float=none|width=30em}} creates the following:

Extended content
Discussion text to be put into box.

Around header text

When used with a section of text, include the section header in the collapsed portion of text. For example, given:

== Heading ==

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Replace with:

Lua error in Module:Shortcut at line 45: attempt to index local 'titleObj' (a nil value).

This template, often abbreviated as {{}}, is used to provide stylized formatting to template displays without actually using the template itself. The code generated will be displayed inline. For a multi-line output, see {{tj}}.

Parameters

With the exception of alttext, the named parameters are toggles that are either omitted (default in most cases) or activated (by being assigned a value such as "on", "yes", "true", "include", etc.). They may be included in any order (see Examples below). Certain templates have the parameter "on" by default; see the main table for all alternate options.

Parameter Action Use with
{{example}}
Default active
Default (without accessory parameters) {{example}}
brace Include braces as part of the template link {{example}} {{tlw}}/{{tn}}
braceinside Include innermost braces as part of the template link {{example}}
bold Renders the template link/name in bold {{example}} {{tlb}}, {{tlxb}}
code Display output using HTML ‎<code>...‎</code> tags (monospaced font) {{example}} {{tlc}}, {{Template link expanded}}, etc.
italic Display any parameters accompanying the template link/name in italics {{example|param}} {{tlxi}}
kbd Display output using HTML ‎<kbd>...‎</kbd> tags (monospaced font) {{example}}
nolink Don't render the template name as a link {{example}} {{tlf}}, {{tnull}}
nowrap Prevent the insertion of line breaks (word wrap) in the output {{example}}
nowrapname Prevent word wrapping in the output of template name/link (parameters will wrap if needed) {{example}}
plaincode Uses ‎<code style="border:none; background:transparent;">...‎</code> {{example}} {{tltss}}
subst Include a subst: prefix before the template link/name {{subst:example}} {{tls}}, {{tlxs}}, etc
alttext=[text] Replace [text] with the actual label to be displayed for the template link {{Other}} {{tla}}
_show_result Will also display the result of the template {{Min|7|-5}} → -5
_expand Will add a link to the expanded template page {{Min|7|-5}} [1]

Unnamed (Positional)

This template can take any number of unnamed parameters as parameters accompanying the template link (or name); see Examples below.

Examples

Code Output Remarks
{{Collapse|Banner}}
Extended content
Banner
Template:Banner does not exist. (Non-existent template is redlinked.)
{{Collapse|Abc}}
Extended content
Abc
Template:Abc exists.
{{Collapse|abC}}
Extended content
abC
Template names are case-sensitive
{{Collapse|abc}}
Extended content
abc
(but the first letter is case-insensitive).
{{Collapse|x0}}
Extended content
x0
no parameters
{{Collapse|x1|one}}
one
x1
one parameter
{{Collapse|x2|one|two}}
one
x2
two parameters
{{Collapse|x3|1|2|3|4|5|6|7|8|9|10}}
1
x3
ten parameters
{{tlg|convert|<nowiki>14|m|ftin|abbr=out|sp=us</nowiki>}}
14|m|ftin|abbr=out|sp=us
convert
Unlimited parameters, as one ‎<nowiki>...‎</nowiki> string.
{{Collapse|x2||two||}}
x2
Empty parameters are discarded.
{{Collapse|x0|code=on}}
Extended content
x0
<code> style
{{Collapse|x0|plaincode=on}}
Extended content
x0
plaincode style
{{Collapse|x0|kbd=on}}
Extended content
x0
<kbd> style
{{Collapse|x0|bold=on}}
Extended content
x0
bold link/name
{{Collapse|x1|one|italic=on}}
one
x1
parameter(s) in italics
{{Collapse|x0|nolink=on}}
Extended content
x0
{{Collapse|x0|subst=on}}
Extended content
x0
{{Collapse|x0|brace=on}}
Extended content
x0
all braces in link
{{Collapse|x0|braceinside=on}}
Extended content
x0
inside braces in link
{{Collapse|x0|alttext=x0 link}}
Extended content
x0
{{Collapse|x0|bold=on|code=on|brace=on}}
Extended content
x0
Combine multiple parameter settings.
{{tlg|x1|{{spaces}}one{{spaces}}}}
 one 
abc
Using {{spaces}} before and after a parameter.
{{Collapse|x2|bold=on|code=on|one|two}}
one
x2
Can combine named and anonymous parameters ...
{{Collapse|x2|one|two|bold=on|code=on}}
one
x2
... in any order ...
{{Collapse|x2|one|code=on|two|bold=on|three}}
one
x2
... even intermixed ...
{{Collapse|x2|one|code=on|two|bold=on|three|italic=on}}
one
x2
... with many configurations.
{{tlg|x1|x=u}}
Extended content
x1
= won't work
{{tlg|x1|x&#61;u}}
x=u
x1
&#61; is okay
{{tlg|x1|x{{=}}u}}
x=u
x1
{{=}} is okay (see Template:=)
{{tlg|x1|x<nowiki>=</nowiki>u}}
x=u
x1
Sticky nowiki is okay.
{{Collapse|x2|3=two|2=one}}
one
x2
Right-to-left is okay
{{Collapse}} Collapse With no arguments, it emits the current page name without braces.
{{Collapse|x2|3=one|4=two}}
Extended content
x2
Null parameter stops parsing.
Wrapping of long names (default)
Code Output
{{Collapse|long template name that would wrap to new line|this is a long value for the 1st parameter that would wrap}}
this is a long value for the 1st parameter that would wrap
long template name that would wrap to new line
Wrapping of long names (nowrap=on)
Code Output
{{Collapse|nowrap=on|long template name that would wrap to new line|long value for the 1st parameter that would wrap}}
long value for the 1st parameter that would wrap
long template name that would wrap to new line
Wrapping of long names (nowrapname=on)
Code Output
{{Collapse|nowrapname=on|long template name that would wrap to new line|long value for the 1st parameter that would wrap}}
long value for the 1st parameter that would wrap
long template name that would wrap to new line

See also

General-purpose formatting

Comparison of template-linking templates according to the styles of generated text and link produced
Text style ↓ {{tlg}} options[note 1]
to achieve text style
Link style
Linked Unlinked Linked with subst Unlinked with subst Linked including braces Linked with alternative text
{{tlg}} options[note 1]
to achieve link style
DEFAULT nolink=yes subst=yes nolink=yes|subst=yes braceinside=yes alttext=Foo
2=Foo
normal DEFAULT {{tlg}}[note 1]
{{tl}}
{{tlp|1|2|...}}[note 2]
{{Template:tlu}}[note 3]
{{tlf}}[note 2]
<template link>
Template loop detected: Template:Tls
{{subst:Template:tlsu}}[note 3]
{{subst:tlsf}}[note 2]
<template link>
{{tn}} {{tla}}
code code=yes {{tl2}}
{{tlx}}
{{Template:tlxu}}[note 3]
{{tlc}}[note 2]
<template link>
{{tnull}}<template link>
{{subst:tlxs}} {{subst:tlsc}}[note 2]
<template link>
monospace plaincode=yes[note 4] {{subst:tltss}}[note 5]
kbd kbd=yes[note 5]
bold bold=yes {{tlb}}
bold+code bold=yes|code=yes {{tlxb}}
italic+code italic=yes|code=yes {{tlxi}}
  1. 1.0 1.1 1.2 {{tlg}} is the most general template, allowing any combination of text style and/or link style options.
  2. 2.0 2.1 2.2 2.3 2.4 Prevents wrapping of text by placing it inside ‎<span class="nowrap">...‎</span> tags.
  3. 3.0 3.1 3.2 Allows links to templates in any namespace.
  4. {{tlg|plaincode=yes}} uses ‎<code style="border:none; background-color:transparent;">...‎</code>.
  5. 5.0 5.1 Displays monospaced font using ‎<span style="font-family:monospace;">...‎</span>.

Other formatting templates

Templates producing specialised formatting effects for given templates, modules or parameters
Code example Effect Notes
{{Tj|Hatnote|Some text|selfref: yes|category: no|lang: fr}}
{{Hatnote
| Some text
| selfref = yes
| category = no
| lang = fr
}}
Supports colors, placeholder texts, named and unnamed parameters
<syntaxhighlight lang="wikitext">
{{Hatnote
   | Some text
   | selfref = yes
   | category = no
   | lang = fr
}}
</syntaxhighlight>
{{Hatnote
    | Some text
    | selfref = yes
    | category = no
    | lang = fr
}}
Same as above
{{Tji|Hatnote|Some text|selfref: yes|category: no|lang: fr}} {{Hatnote|Some text|selfref=yes|category=no|lang=fr}} Supports colors, placeholder texts, named and unnamed parameters
<syntaxhighlight lang="wikitext" inline>{{Hatnote|Some text|selfref=yes|category=no|lang=fr}}</syntaxhighlight> {{Hatnote|Some text|selfref=yes|category=no|lang=fr}} Same as above
{{tl2|Hatnote|lang=fr}} {{hatnote}} Supports linking to sister projects (e.g., fr:Hatnote)
{{demo|<nowiki>{{Hatnote|lang=fr|Some text}}</nowiki>}}
{{hatnote|lang=fr|Some text}}
Shows code and example
{{tln|Hatnote}} Template:Hatnote Produces a normal link to the template
{{elc|Template:Hatnote}}
{{elc|Template:Hatnote|Hatnote}}
[[Template:Hatnote]]
[[Template:Hatnote|Hatnote]]
Formats wikilink, with optional piped link text and blended suffix
{{ml|Example|hello}} {{#invoke:Example|hello}} Counterpart to {{tl}} for linking to Lua modules
{{mfl|Example|hello}} {{#invoke:Example|hello}} Similar to {{ml}}, but expects the function to be documented and creates a link to the corresponding section
{{mlx|Example|hello}} {{#invoke:Example|hello}} Counterpart to {{tlx}} for linking to Lua modules
{{ml-lua|Module:Example|hello}} require('Module:Example') Link to Lua modules and built-in libraries, showing Lua code.
{{para|title|<var>book title</var>}} |title=book title Formats template parameters for display, with or without values
{{sclx|LASTING}} [[WP:LASTING]] Takes a shortcut suffix in project namespace and displays it with brackets and the WP: alias in a ‎<code>...‎</code> tag.
{{tag|ref}}
{{xtag|templatedata}}
‎<ref>...‎</ref>
<templatedata>
Formats [X]HTML tags; can add content, choose opening, closing, or self-closing
{{dtl|Ping project}} {{d:Ping project}} Wikidata counterpart to {{tl}}
{{pf|if}}
{{pf|if|{{{1}}}|true|false}}
{{#if}}
{{#if:{{{1}}}|true|false}}
Parser function equivalent to {{tl}}
{{magic word|uc:}} {{uc:}} Magic word links

With utility links

Templates producing utility links for a given template (Hatnote used here as example)
Code example Effect
{{lt|Hatnote}} [[Template:]] 
{{lts|Hatnote}} Template:Hatnote(edit talk links history)
{{t links|Hatnote}} {{Hatnote}} (edit talk history links # /subpages /doc /doc edit /sbox /sbox diff /test)
{{tfd links|Hatnote}} Template:Hatnote (talk · history · transclusions · logs · subpages)
{{tetl|Hatnote}} {{Hatnote}}
links talk edit
{{tsetl|Hatnote}} {{subst:Hatnote}}
 links talk edit
{{ti|Hatnote}} {{Hatnote}}
{{tic|Hatnote}} Template:Hatnote (talk links edit)
{{tim|Hatnote}} m:Template:Hatnote (backlinks edit)
{{tiw|Hatnote}} Template:Hatnote (backlinks edit)
{{tlt|Hatnote}} {{Hatnote}} (talk)
{{ttl|Hatnote}} {{Hatnote}} (t/l)
{{twlh|Hatnote}} Template:Hatnote (links, talk)

The expand parameter

Simply add |expand=yes to have the box show up in expanded form with a "hide" link, instead of collapsed form with a "show" link. Other options: |expand= yes, y, expand, expanded, uncollapse, uncollapsed. Note: |expand=no will fold the box (default).

The clear parameter

In some situations you may not want the default clear: both; CSS to apply, which puts the collapse box below any left- or right-floated content within the same HTML block. In this case, you can use |clear=none, |clear=right, or |clear=left, as needed.

When content includes tables

This template frequently breaks when used around content that consists of or includes wikitables. Such content can be made collapsible by using the {{collapse top}} and {{collapse bottom}} templates instead of {{collapse}}.

If you want to collapse only the table and not other content, you can do this using wikitable parameters. See the Collapsing tables guide for help.

Limitations

{{#section-h:Help:Collapsing|Limitations}}

TemplateData

This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. Click here to see a monthly parameter usage report for this template in articles based on this TemplateData.

TemplateData for Collapse

Creates a collapsible box that allows its content to be hidden or revealed on user's command. It is used to reduce clutter.

Template parameters

ParameterDescriptionTypeStatus
Contents1 content text

Contents of the box

Contentrequired
Title2 title heading header reason result

Text of title bar. Defaults to "Extended contents".

Default
Extended content
Stringsuggested
Expanded by default?expand

Setting to "yes" (or "y", "expand", "expanded", "uncollapse", or "uncollapsed") will cause the box to show its contents by default. Any other value (and omitting this parameter) causes the box to be expanded by default. If not set or set to another value (e.g. "no") the box will be collapsed by default (its contents hidden).

Default
no
Stringoptional
Border widthborder

Width of the outermost border. Accepts a number (e.g. 2) followed immediately with a CSS-compatible unit of measurement. (e.g. "px") Example: 2px.

Default
1px
Stringoptional
Title bar's colorbg background

Color of the title bar. Can be set any valid CSS color value but please take care that text would remain black.

Default
#F0F2F5
Stringoptional
Paddingpadding

Width of the padding, the empty space between border and the contents. Accepts a number (e.g. 2) followed immediately with a CSS-compatible unit of measurement. (e.g. "px") Example: 2px.

Default
8px
Unknownoptional
Outer backgroundbg1

Color of the space between the inner and outer border. Can be set to any valid CSS color.

Default
transparent
Stringoptional
Outer border colorb-color

Color of the outer border. Can be any valid CSS color.

Default
silver
Stringoptional
Collapse box widthwidth

The width of the entire collapsed box.

Default
100%
Stringoptional
Center-align titlecenter

If set to any value, the title will be centered.

Booleanoptional
Font colorfc

Font color for the title. Also sets the color of the [show]/[hide] link. Can be any valid CSS color

Stringoptional
CSS classclass

Additional CSS class to add

Stringoptional
CSS floatfloat

CSS float, one of "left", "right", "none", "center"/"centre", or blank.

Stringoptional
CSS clearclear

CSS clear value. The default depends on the selected float. Usually one of "none", "left", "right", or "both"

Stringoptional
Left-align titleleft

Left-aligns the title. Takes precedence over center.

Booleanoptional
Content borderborder2

CSS border styling to add to the content.

Default
1px silver
Stringoptional
Content background colorbg2

Background color to use for expanded content.

Default
white
Stringoptional

Re-using at other wikis

This template depends upon having rules for the three classes (collapsible, uncollapsed, and collapsed) in the appropriate CSS files, and some related JavaScript installed. This template transcludes {{main other}} and {{lorem ipsum}}, which should also be imported at the same time.

For MediaWiki versions ≥ 1.18, this template can simply be exported and then imported into another MediaWiki installation. Some changes to the source code will need to be made in order for this template to become usable on the Main/Article (ns:0) namespace.

The toggle text can be edited at external Wiki's MediaWiki:Collapsible-expand and MediaWiki:Collapsible-collapse pages. Further information at jquery.makeCollapsible module.

See also

#invoke:Navbox