Template:Excerpt/sandbox
This is the template sandbox page for Template:Excerpt (diff). See also the companion subpage for test cases. |
This template is used on approximately 12,000 pages and changes may be widely noticed. Test changes in the template's /sandbox or /testcases subpages, or in your own user subpage. Consider discussing changes on the talk page before implementing them. |
This template uses Lua: |
This template is used for reusing parts of pages in other pages. This practice has various advantages and disadvantages.
This template extends the capabilities of the built-in normal transclusion and labeled section transclusion.
Usage
[edit]{{Excerpt|Page title}}
– Transclude the lead section (example){{Excerpt|Page title|Section title}}
– Transclude a specific section, excluding any subsections (example)
Parameters
[edit]There is one required parameter, and numerous optional ones for configuring the excerpt:
Summary
[edit]Source identification
|1=
– Name of the article or page to transclude. Required. Aliases:|article=
or|page=
.|2=
– Name of the section or tag to transclude. Optional; if omitted, transcludes the lead section (content above the first section header). Aliases:|section=
or|fragment=
.
Transclusion config
Transcludable content is defined as one of several element types: file
, list
, paragraph
, reference
, subsection
, table
, or template
.
Config parameters specify which element type to transclude, and in some cases, how many and which items of that type to transclude. All config parameters are optional; if omitted, all items of all element types are transcluded from the source page identified by the two unnamed parameters. Some element types support conditional item transclusion by specifying an item number range (1-3) or comma series (1, 2, 5); these types include: files, lists, paragraphs, and tables.
There are ten optional transclusion configuration parameters:
|only=
– Element types to transclude. Values:file(s)
,list(s)
,table(s)
,template(s)
,paragraph(s)
. Default: all element types.|files=
– Files to transclude. Default: all files. Same basic syntax as|paragraphs=
, but see § Details.|onlyfreefiles=no
– Enables transclusion of non-free files. Default: exclude non-free content.
|links=no
– Unlink all wikilinks and render as plain text.|lists=
– Lists (bulleted, numbered) to transclude. Default: all lists. Same syntax as for|paragraphs=
.|paragraphs=
– Paragraphs to transclude. Default: all paragraphs.|references=no
– Exclude all references between<ref>...</ref>
tags.|subsections=yes
– Include subsections of the transcluded section. Default: only content above the first subsection header.|tables=
– Tables to transclude. Default: all tables. Same basic syntax as|paragraphs=
, but see § Details.|templates=
– Templates to transclude. By default all templates are transcluded, except those blacklisted at Module:Excerpt/config. See § Details for how to specify a specific template or templates for inclusion or exclusion.
Style and extra features
These optional parameters alter the way transcluded items are displayed:
|bold=yes
– Preserve bold text.|briefdates=yes
– Abbreviate birth and death information to (YYYY-YYYY) format|displaytitle=
– Change the text of the link in the hatnote. For example, add italics, subscripts, etc.|hat=no
– Hide the hatnote "This section is an excerpt from..."|inline=yes
– Remove the<div>
tags around the excerpt, to use it inside other text, or to add references or other content after it with no paragraph break between them. Also hides the hatnote; to reestablish it, use {{transclusion notice}} above the Excerpt invocation.|quote=yes
– Wrap the excerpt with<blockquote>
tags.|this=
– Change the initial text of the hatnote. For example, if the transcluded content is a gallery, you can set|this=This gallery is
so that the hatnote reads "This gallery is an excerpt from..."
Details
[edit]|1=
or|article=
or|page=
- By default the lead section is transcluded (example). If the page contains an infobox, the image and caption of the infobox will be transcluded (unless
|files=0
is set). Also, templates listed at Module:Excerpt/config will not be transcluded (unless requested explicitly with|templates=
, see below).
- By default the lead section is transcluded (example). If the page contains an infobox, the image and caption of the infobox will be transcluded (unless
|2=
or|section=
or|fragment=
- Name of the section to transclude (example) or of the
<section>
tag to transclude (example). In the case of a section tag, the section must be marked with<section begin="Name of the fragment" />
and<section end="Name of the fragment" />
in the page to be transcluded. Notice that this template provides other ways of targeting specific fragments of a page without having to resort to section tags.
- Name of the section to transclude (example) or of the
|only=
- The element type to transclude, excluding all other types. By default all element types are transcluded. Param
|only=
is an exclusionary param, and excludes all other types of elements, except the one you name, so that for example, specifying|only=paragraphs
excludes all lists, tables, templates, and so on. Param values can be in the singular (e.g.,|only=paragraph
) or plural (e.g.,|only=paragraphs
) and mean different things: in the singular, only the first item of that element type is transcluded; in the plural, all items are.|only=file
– Transclude only the first file (but no lists, paragraphs, tables, etc.)|only=files
– Transclude all files (but nothing else)|only=list
– Transclude only the first list, exclude all other element types|only=lists
– Transclude all lists (but nothing else)|only=table
– Transclude only the first table, exclude all other element types|only=tables
– Transclude all tables (but nothing else) (example)|only=template
– Transclude only the first template (excluding templates blacklisted at Module:Excerpt/config, as well as all other element types)|only=templates
– Transclude all templates (excluding blacklisted templates), (but nothing else)|only=paragraph
– Transclude only the first paragraph, exclude all other element types|only=paragraphs
– Transclude all paragraphs (but nothing else)
- The element type to transclude, excluding all other types. By default all element types are transcluded. Param
|files=
- An element item param, defining which files to transclude. Default: all files.
|files=A.jpg
– Transclude the file named 'A.jpg'|files=A.jpg, B.png, C.gif
– Transclude the files named 'A.jpg', 'B.png' and 'C.gif'|files=.+%.png
– Transclude all PNG files|files=-A.jpg
– Transclude all files except the one named 'A.jpg'|files=-A.jpg, B.png, C.gif
– Transclude all files except the ones named 'A.jpg', 'B.png' and 'C.gif'|files=-.+%.png
– Transclude all non-PNG files
- An element item param, defining which files to transclude. Default: all files.
|paragraphs=
- An element item param, defining which paragraphs to transclude. By default all paragraphs are transcluded.
|paragraphs=0
– Transclude no paragraphs|paragraphs=1
– Transclude the first paragraph|paragraphs=2
– Transclude the second paragraph|paragraphs=1,3
– Transclude the first and third paragraphs|paragraphs=1-3
– Transclude the first, second and third paragraphs|paragraphs=1-3,5
– Transclude the first, second, third and fifth paragraphs|paragraphs=-1
– Transclude all paragraphs except the first|paragraphs=-2
– Transclude all paragraphs except the second|paragraphs=-1,3
– Transclude all paragraphs except the first and third|paragraphs=-1-3
– Transclude all paragraphs except the first, second and third|paragraphs=-1-3,5
– Transclude all paragraphs except the first, second, third and fifth
- An element item param, defining which paragraphs to transclude. By default all paragraphs are transcluded.
|subsections=yes
- An element item param, defining which subsections of the source to transclude. Default: only the portion of the source lying above the first subsection header. Notice that if the transclusion is done from a section level 3 in the transcluding page, and the transcluded subsections are also level 3, then transcluded subsections will show with the same hierarchy as the transcluding section, which may not be the desired outcome, so use with caution.
|tables=
- An element item param, defining which tables to transclude. Default: all tables. Same syntax as when transcluding paragraphs, but also:
|tables=Stats2020
– Transclude the table with id 'Stats2020'|tables=Stats2020, Stats2019, Stats2018
– Transclude the tables with ids 'Stats2020', 'Stats2019' and 'Stats2018'|tables=-Stats2020
– Transclude all tables except the one with id 'Stats2020'|tables=-Stats2020, Stats2019, Stats2018
– Transclude all tables except the ones with ids 'Stats2020', 'Stats2019' and 'Stats2018'
- An element item param, defining which tables to transclude. Default: all tables. Same syntax as when transcluding paragraphs, but also:
|templates=
- An element item param, defining which templates to transclude. Default: all templates except those blacklisted at Module:Excerpt/config. Using a hyphen (minus sign) before a comma-delimited list of templates excludes those templates from transclusion.
|templates=-Ocean
– Add the template 'Ocean' to the blacklist|templates=-Ocean, Nature
– Add the templates 'Ocean' and 'Nature' to the blacklist|templates=Infobox person
– Ignore the blacklist and transclude the template 'Infobox person'|templates=Infobox person, Ocean
– Ignore the blacklist and transclude the templates 'Infobox person' and 'Ocean'|templates=.*
– Ignore the blacklist and transclude all templates
- An element item param, defining which templates to transclude. Default: all templates except those blacklisted at Module:Excerpt/config. Using a hyphen (minus sign) before a comma-delimited list of templates excludes those templates from transclusion.
Tips and how-to
[edit]Compared to #section
[edit]For simple cases of transcluding sections of articles, the {{#section}}, {{#section-x}}, and {{#section-h}} (abbreviated {{#lst}}, {{#lstx}}, and {{#lsth}})) parser functions can be used instead of this template. {{#lsth:article|fragmentname}} will transclude the section of "article" with the header "fragmentname", and {{#lsth:article}} will transclude the lead section of "article". Excerpting only specific paragraphs can be done by marking up the source article with <section begin=fragmentname/>...<section end=fragmentname/>
tags and using {{#lst:article|fragmentname}} to transclude those fragments, which is equivalent to using the |fragment=fragmentname
parameter with this template. {{#lsth:article|fragmentname}} can also be used to transclude everything but those fragments.
The text will not be trimmed of excess whitespace, there will not be a header (equivalent to |hat=no
, and all files, templates, tables, references, and subsections will be included unless the source article is marked up with <section begin=fragmentname/>...<section end=fragmentname/>
, <noinclude>...</noinclude>
, or <onlyinclude>...</onlyinclude>
tags. Self links will appear in bold.
Differing citation styles
[edit]It can happen that the source you want to excerpt contains footnotes in a different citation style than your article, and excerpting the source would cause a citation style mismatch, which is contrary to the guideline on citing sources. Sometimes, excerpt can still be used, while avoiding a mismatch in style, by the use of params |references=no
and |inline=yes
.
If the source you want to excerpt has multiple ref-tags interspersed throughout the source, and they need to display exactly in those locations in order to maintain full verifiability, then this source might not be a good candidate for transclusion via the {{excerpt}} template, and copying the content from the source into the article might be a better choice.
However, if the source page you want to excerpt has either:
- references mostly or all at the end of the text, or
- references scattered throughout the source, but which could legitimately be regrouped at the end of the excerpt without adversely affecting verifiability,
then you can do it. To implement this, use params |references=no
to strip the ref-tags from the transcluded content, and |inline=yes
to define the excerpt as an inline display element in order to § Suppress line breaks between paragraphs, and then manually append a copy of all the references in the source immediately after the excerpt tag ending curly braces in the target article, with no intervening line breaks, white space, or other characters between the tag and the appended references. The copied references will have to be manually converted from short footnote-style to full, inline citation-style, or vice-versa, to match the citation style of the target.
Excerpt trees
[edit]When a very general article uses excerpts from more specific articles, which in turn use excerpts from even more specific articles, then a tree structure emerges, called an "Excerpt tree".
Here you can navigate the main excerpt trees on the English Wikipedia. It's useful for editors interested in expanding or improving them. To navigate the trees, click the following button(S):
Refinement using inclusion control
[edit]Sometimes, a passage will almost fit for a transclusion, but not quite. In these cases, you can edit the source page to add <noinclude>...</noinclude>
tags around content you don't want in the excerpt and <includeonly>...</includeonly>
tags around content you want only in the excerpt.
For instance, the page COVID-19 misinformation begins with "The COVID-19 pandemic has resulted in misinformation...". However, when excerpting this lead to the misinformation section of COVID-19 pandemic, we don't need to specify which pandemic we're referring to. Therefore, the code The <noinclude>[[COVID-19 pandemic]]</noinclude><includeonly>pandemic</includeonly> has resulted in [[misinformation]]
can be used at the misinformation page, so that it will appear at the pandemic page as "The pandemic has resulted in misinformation...".
For pages with a high volume of edits, it may be a good idea to leave a hidden comment explaining why the tags are there, so that no one will be tempted to remove them, like so: The <noinclude>[[COVID-19 pandemic]]</noinclude><!--These tags are used to refine the excerpt at [[COVID-19 pandemic]]--><includeonly>pandemic</includeonly> has resulted in [[misinformation]]
Please note that when the </noinclude>
tag is wrapped into a new line, a character next to it would be interpreted as a line beginning. This can lead to some formatting problems. For example, when a </noinclude>
at line beginning is succeeded by a whitespace character, the page engine would translate this as a leading space that renders the subsequent paragraph in code block and monospaced font with preserved formatting. For this reason, no spaces should separate the </noinclude>
tag from the text it precedes.
Replacing summary section with excerpt of child article
[edit]A section is often a summary in a parent article of a more detailed page about a subtopic located in a child page; these are generally linked with Template:Main in the parent. Sometimes it's convenient to replace the content of such a summary section in the parent with an excerpt of the child page lead (after merging any valuable content of the section into the child page). In such cases, an efficient way to proceed is:
- Open the parent section for editing in one tab, and the child article in another.
- Copy the text of the parent section and append it to the lead section of the child page.
- Consolidate and adjust the combined lead using common sense.
- Save the changes in the child article with an edit summary like: "Copied content from [[Page]]. See that article's history for attribution."
- Back in the parent page section, delete all content except the section header and replace it with an excerpt of the child page.
- Save the changes in the section; proposed edit summary: "Moved section content to [[Child page title]] and replaced with excerpt."
IMPORTANT: Include the full edit summary to comply with Wikipedia's copyright policy. If you forget to do this, follow the instructions on Wikipedia:Copying text from other sources to create a dummy edit with the required edit summary. |
Suppress line breaks between paragraphs
[edit]If you want to merge two excerpted paragraphs from a source into one longer one in your article, use two excerpts instead of one, and change the display mode to inline. So, for example, instead of this :
{{excerpt|Ocean color|paragraphs=2-3|file=no}}
// (example taken from Ocean#Color)
you could code:
{{excerpt|Ocean color|paragraphs=2|file=no|inline=yes}}
{{excerpt|Ocean color|paragraphs=3|file=no|inline=yes}}
and this will remove the line break between the two paragraphs, so they will render as one paragraph.
By default, an {{excerpt}} generates an HTML div-tag, which is a block-level display element, so contiguous excerpts are normally separate block elements with line breaks between them. This can be overridden through use of param |inline=yes
, which suppresses the div-tag, and results in an inline display element instead. In this case, just as with running text on adjacent lines of wikicode, no line break is generated between them.
This technique can also be adapted to § change citation style or use different references.
Advantages and disadvantages
[edit]The use of {{Excerpt}} has the following advantages:
- Reduces maintenance by avoiding duplicate content that must be updated multiple times
- Improves content quality by encouraging editors to merge related content, rather than having multiple versions in various stages of development (see #Replacing summary section with excerpt of child article)
- Fosters collaboration by channeling contributors into one place, rather than working in parallel
- Promotes rapid development of articles, especially those written in summary style
It also has the following disadvantages:
- Impediment to editing as you have to go to the sub article to make changes to the main article (though excerpts include a hatnote with an [edit] button to edit the excerpted article in one click)
- Reduces accuracy as an excerpt of one article is not always a perfect fit into a new article (but see #Refinement using inclusion control)
- Decreases visibility as changes to the sub article will not appear on the watchlist of editors of the main article (see phab:T55525)
- Risk of linkrot as pages or sections are blanked, moved, or deleted; this may result in the appearance of § error messages on the page (but all broken excerpts are automatically tracked at Category:Articles with broken excerpts and regularly fixed).
- Duplicated references since references are pulled from the source article and the destination article may already have the reference (but see § Differing citation styles above).
Incompatibilities
[edit]Error messages
[edit]If an error is detected, an error message will appear in the article in place of the expected transcluded content:
- No page given – No page was passed to the template
- Title X is not valid – The title passed is not valid (contains forbidden characters such as < or >)
- Page X not found – The page passed does not exist, or the page is a redirect and the target page was not found
- Lead section is empty – The page exists, but cannot excerpt from non-existent lead
- Section X not found – The page exists, but cannot excerpt the desired section because either:
- The given section does not exist. This may occur if the source page section is removed or renamed. To help mitigate this, see MOS:BROKENSECTIONLINKS.
- The given section exists, but is excluded from transclusion by one of the inclusion control tags.
- Section X is empty – The given section exists, but is empty
- Template loop detected – The excerpted section contains itself an excerpt. While this is not strictly a template loop, the software considers it so. To fix it, skip the intermediate excerpt (example).
See also
[edit]- Module:Excerpt
- Module:Excerpt/config
- Module:Transcluder
- c:Data:I18n/Module:Excerpt.tab
- Help:Transclusion#Drawbacks
- Category:Articles with excerpts, or Articles that link to "Template:Excerpt" (unsorted)
- Category:Articles with broken excerpts
- Help:Labeled section transclusion – A more efficient method for simple section transclusions
- Wikipedia:Transclusion#Selective transclusion – how to transclude one or more sections of an article or project page into another
- Wikipedia:Summary style#Synchronization
- Wikipedia:Manual of Style/Lead section
- Wikipedia:WikiProject Introductions
- {{Transclude lead excerpt}} and {{Transclude linked excerpt}} – templates designed for excerpt transclusion in portals
- {{Transcluded section}} – creates hatnote but does not transclude the section
- {{Transcluding article}} – transcludes one or more entire pages
- {{Template parameter value}} – extracts the value of a parameter passed to a template
- meta:Grants:Project/Rapid/Sophivorus/Excerpts - Grant to spread excerpts to various Wikipedias
- meta:Concise Wikipedia - Perennial new project proposal (see the comparison table at the bottom in particular)
- Single source of truth
- Excerpts: Modular and Reusable Content within Wikipedia - Video presentation about excerpts for Wikimania 2021
- Template:Get cell - Template to transclude specific table cells for calculation purposes
Template data
[edit]This template is used for transcluding part of an article into another article.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Article | 1 article page | Name of the article or page to transclude
| Page name | required |
Section | 2 section fragment | Name of the section or <section> tag to transclude
| String | optional |
Only | only | Transclude only this kind of element
| String | optional |
Paragraphs | paragraphs paragraph | Paragraphs to transclude
| String | optional |
Files | files file | Files to transclude
| String | optional |
Tables | tables table | Tables to transclude
| String | optional |
Lists | lists list | Lists to transclude
| String | optional |
Templates | templates template | Templates to transclude
| String | optional |
References | references | Whether to transclude the references
| Boolean | optional |
Subsections | subsections | Whether to transclude the subsections of the requested section
| Boolean | optional |
Hatnote | hat | Whether to include the hatnote
| Boolean | optional |
Bold | bold | Whether to preserve bold text
| Boolean | optional |
Wikilinks | links | Whether to preserve wikilinks
| Boolean | optional |
Quote | quote | Wraps the excerpt in <blockquote> tags
| Boolean | optional |
This | this | Change the initial text of the hatnote
| String | optional |
Display title | displaytitle | Change the text of the link in the hatnote | String | optional |
Inline | inline | Remove the hatnote and <div> tags around the excerpt, to use it inside other text
| Boolean | optional |
Only free files | onlyfreefiles | Enable transclusion of non-free files
| Boolean | optional |
Brief dates | briefdates | Abbreviate birth and death information to (YYYY-YYYY) format
| Boolean | optional |
Class | class | Additional CSS class
| String | optional |