Controlling template inclusion[]
There are 3 tags that can be used in a template to control how certain portions of the text are treated when the template is included.
<includeonly>
- This tag specifies a portion of text that is only displayed when the template is included on another page; it will not be displayed on the template's own page.
<noinclude>
- This tag specifies a portion of text that is only displayed on the template's own page; it will not be displayed when the template is included on another page.
<onlyinclude>
- This tag specifies a portion of text that will be the only content displayed when the template is included on another page; it will also display on the template's own page.
This can be easier to understand if you think of the tags in pairs.
<includeonly>
and<noinclude>
are opposites:<includeonly>
is only displayed when the template is included somewhere else, and<noinclude>
is only displayed on the template's page.
<noinclude>
and<onlyinclude>
are complementary: wrapping one section of text with<noinclude>
gives the same result as if the other content had been wrapped with<onlyinclude>
.- Example:
A<onlyinclude>B</onlyinclude>
is identical to<noinclude>A</noinclude>B
- Example:
Nesting[]
The only nesting of these tags that makes sense is to use <includeonly>
inside <onlyinclude>
.
Demonstration[]
Tag | Template code | Shown on template page | Shown on article that includes template |
---|---|---|---|
includeonly | Section A <includeonly>Section B</includeonly> |
Section A | Section A Section B |
noinclude | Section A <noinclude>Section B</noinclude> |
Section A Section B |
Section A |
onlyinclude | Section A <onlyinclude>Section B</onlyinclude> |
Section A Section B |
Section B |
includeonly + onlyinclude |
Section A <onlyinclude>Section B <includeonly>Section C</includeonly></onlyinclude> |
Section A Section B |
Section B Section C |
Usage scenarios[]
- To auto-categorize all pages that use a template, but not the template itself, use:
<includeonly>[[Category:foo]]</includeonly>
- To display documentation on a template, use:
<onlyinclude>Template code</onlyinclude> Template documentation
- To display in-line comments directly inside a template but hide them from articles, use
Template code <noinclude>In-line comment</noinclude> Template code