Difference between revisions of "Template:Excerpt"
m (1 revision imported) |
m (Translate extension now adds untranslated anchors) |
||
Line 1: | Line 1: | ||
− | <includeonly>{{#invoke:Excerpt|main | + | <noinclude> |
− | | 1 = {{{ | + | <languages /> |
− | | | + | </noinclude><includeonly>{{#invoke:Excerpt|main}}</includeonly><noinclude> |
− | }}</ | + | {{Documentation|content= |
+ | |||
+ | {{Lua|Module:Excerpt}} | ||
+ | <translate><!--T:111--> This template is used for reusing parts of pages in other pages.</translate> | ||
+ | <translate><!--T:112--> This practice has several advantages:</translate> | ||
+ | |||
+ | <translate> | ||
+ | <!--T:113--> | ||
+ | * '''Reduces maintenance''' by avoiding duplicate content that must be updated multiple times</translate> | ||
+ | <translate> | ||
+ | <!--T:114--> | ||
+ | * '''Improves content quality''' by encouraging editors to merge related content, rather than having multiple versions in various stages of development</translate> | ||
+ | <translate> | ||
+ | <!--T:115--> | ||
+ | * '''Fosters collaboration''' by channeling contributors into one place, rather than working in parallel | ||
+ | |||
+ | <!--T:116--> | ||
+ | This template extends the capabilities of the built-in [[<tvar name=1>Special:MyLanguage/Transclusion</tvar>|normal transclusion]]. | ||
+ | |||
+ | == Usage == <!--T:2--> | ||
+ | |||
+ | === Basic usage === <!--T:3--> | ||
+ | </translate> | ||
+ | * <code><nowiki>{{Excerpt|Page title}}</nowiki></code> — <translate><!--T:4--> Transclude the lead section ([[<tvar name=1>#Lead section</tvar>|example]])</translate> | ||
+ | * <code><nowiki>{{Excerpt|Page title|Section title}}</nowiki></code> — <translate><!--T:5--> Transclude a specific section, excluding any subsections ([[<tvar name=1>#Specific section</tvar>|example]])</translate> | ||
+ | |||
+ | <translate> | ||
+ | === Parameters === <!--T:6--> | ||
+ | </translate> | ||
+ | * <code>1</code> — <translate><!--T:7--> Title of the page to transclude.</translate> <translate><!--T:8--> '''Only required parameter.'''</translate> <translate><!--T:9--> By default the lead section will be transcluded ([[<tvar name=1>#Lead section</tvar>|example]]).</translate> | ||
+ | * <code>2</code> — <translate><!--T:10--> Title of the section to transclude ([[<tvar name=1>#Specific section</tvar>|example]]) or name of the [[<tvar name=2>Special:MyLanguage/Extension:Labeled Section Transclusion#How it works</tvar>|<tvar name=3>{{tag|section|open}}</tvar> tag]] to transclude.</translate> <translate><!--T:119--> Notice that this template provides other ways of targeting specific elements of a page without having to resort to section tags.</translate> | ||
+ | * <code>only</code> — <translate><!--T:11--> Elements to transclude ([[<tvar name=1>#Files only</tvar>|example]]).</translate> <translate><!--T:86--> By default all elements are transcluded.</translate> | ||
+ | ** <code>only=file</code> <translate><!--T:106--> or</translate> <code>only=files</code> — <translate><!--T:12--> Transclude only files</translate> | ||
+ | ** <code>only=list</code> <translate><!--T:107--> or</translate> <code>only=lists</code> — <translate><!--T:13--> Transclude only lists</translate> | ||
+ | ** <code>only=table</code> <translate><!--T:108--> or</translate> <code>only=tables</code> — <translate><!--T:14--> Transclude only tables</translate> | ||
+ | ** <code>only=template</code> <translate><!--T:109--> or</translate> <code>only=templates</code> — <translate><!--T:16--> Transclude only templates</translate> | ||
+ | ** <code>only=paragraph</code> <translate><!--T:110--> or</translate> <code>only=paragraphs</code> — <translate><!--T:18--> Transclude only paragraphs</translate> | ||
+ | * <code>paragraphs</code> — <translate><!--T:21--> Paragraphs to transclude.</translate> <translate><!--T:22--> By default all paragraphs are transcluded.</translate> | ||
+ | ** <code>paragraphs=0</code> — <translate><!--T:24--> Transclude no paragraphs</translate> | ||
+ | ** <code>paragraphs=1</code> — <translate><!--T:25--> Transclude the first paragraph</translate> | ||
+ | ** <code>paragraphs=2</code> — <translate><!--T:26--> Transclude the second paragraph</translate> | ||
+ | ** <code>paragraphs=1,3</code> — <translate><!--T:27--> Transclude the first and third paragraphs</translate> | ||
+ | ** <code>paragraphs=1-3</code> — <translate><!--T:28--> Transclude the first, second and third paragraphs</translate> | ||
+ | ** <code>paragraphs=1-3,5</code> — <translate><!--T:29--> Transclude the first, second, third and fifth paragraphs</translate> | ||
+ | ** <code>paragraphs=-1</code> — <translate><!--T:30--> Transclude all paragraphs except the first</translate> | ||
+ | ** <code>paragraphs=-2</code> — <translate><!--T:31--> Transclude all paragraphs except the second</translate> | ||
+ | ** <code>paragraphs=-1,3</code> — <translate><!--T:32--> Transclude all paragraphs except the first and third</translate> | ||
+ | ** <code>paragraphs=-1-3</code> — <translate><!--T:33--> Transclude all paragraphs except the first, second and third</translate> | ||
+ | ** <code>paragraphs=-1-3,5</code> — <translate><!--T:34--> Transclude all paragraphs except the first, second, third and fifth</translate> | ||
+ | * <code>lists</code> — <translate><!--T:87--> Lists to transclude.</translate> <translate><!--T:88--> By default all lists are transcluded.</translate> <translate><!--T:89--> Same syntax as when transcluding paragraphs.</translate> | ||
+ | * <code>files</code> — <translate><!--T:35--> Files to transclude.</translate> <translate><!--T:36--> By default all files are transcluded.</translate> <translate><!--T:60--> Same syntax as when transcluding paragraphs, but also:</translate> | ||
+ | ** <code>files=A.jpg</code> — <translate><!--T:38--> Transclude the file named '<tvar name=1>A.jpg</tvar>'</translate> | ||
+ | ** <code>files=A.jpg, B.png, C.gif</code> — <translate><!--T:39--> Transclude the files named '<tvar name=1>A.jpg</tvar>', '<tvar name=2>B.png</tvar>' and '<tvar name=3>C.gif</tvar>'</translate> | ||
+ | ** <code>files=.+%.png</code> — <translate><!--T:40--> Transclude all PNG files</translate> | ||
+ | ** <code>files=-A.jpg</code> — <translate><!--T:41--> Transclude all files except the one named '<tvar name=1>A.jpg</tvar>'</translate> | ||
+ | ** <code>files=-A.jpg, B.png, C.gif</code> — <translate><!--T:42--> Transclude all files except the ones named '<tvar name=1>A.jpg</tvar>', '<tvar name=2>B.png</tvar>' and '<tvar name=3>C.gif</tvar>'</translate> | ||
+ | ** <code>files=-.+%.png</code> — <translate><!--T:43--> Transclude all non-PNG files</translate> | ||
+ | * <code>tables</code> — <translate><!--T:44--> Tables to transclude.</translate> <translate><!--T:45--> By default all tables are transcluded.</translate> <translate><!--T:46--> Same syntax as when transcluding paragraphs, but also:</translate> | ||
+ | ** <code>tables=Stats2020</code> — <translate><!--T:47--> Transclude the table with id '<tvar name=1>Stats2020</tvar>'</translate> | ||
+ | ** <code>tables=Stats2020, Stats2019, Stats2018</code> — <translate><!--T:48--> Transclude the tables with ids '<tvar name=1>Stats2020</tvar>', '<tvar name=2>Stats2019</tvar>' and '<tvar name=3>Stats2018</tvar>'</translate> | ||
+ | ** <code>tables=-Stats2020</code> — <translate><!--T:49--> Transclude all tables except the one with id '<tvar name=1>Stats2020</tvar>'</translate> | ||
+ | ** <code>tables=-Stats2020, Stats2019, Stats2018</code> — <translate><!--T:50--> Transclude all tables except the ones with ids '<tvar name=1>Stats2020</tvar>', '<tvar name=2>Stats2019</tvar>' and '<tvar name=3>Stats2018</tvar>'</translate> | ||
+ | * <code>templates</code> — <translate><!--T:90--> Templates to transclude.</translate> <translate><!--T:91--> By default all templates are transcluded.</translate> <translate><!--T:92--> Same syntax as when transcluding paragraphs, but also:</translate> | ||
+ | ** <code>templates=Infobox</code> — <translate><!--T:93--> Transclude the template '<tvar name=1>Infobox</tvar>'</translate> | ||
+ | ** <code>templates=Infobox, Navbox, Chart</code> — <translate><!--T:94--> Transclude the template '<tvar name=1>Infobox</tvar>', '<tvar name=2>Navbox</tvar>' and '<tvar name=3>Chart</tvar>'</translate> | ||
+ | ** <code>templates=-Infobox</code> — <translate><!--T:95--> Transclude all templates except '<tvar name=1>Infobox</tvar>'</translate> | ||
+ | ** <code>templates=-Infobox, Navbox, Chart</code> — <translate><!--T:96--> Transclude all templates except '<tvar name=1>Infobox</tvar>', '<tvar name=2>Navbox</tvar>' and '<tvar name=3>Chart</tvar>'</translate> | ||
+ | * <code>this</code> — <translate><!--T:100--> Change the initial text of the hatnote. For example, if the transcluded content is a gallery, you can set <tvar name=1><code>this=This gallery is</code></tvar> so that the hatnote reads "This gallery is an excerpt from..."</translate> | ||
+ | * <code>hat=no</code> — <translate><!--T:101--> Hide the hatnote "This section is an excerpt from..."</translate> | ||
+ | * <code>more=yes</code> — <translate><!--T:120--> Show a "Read more..." link at the end</translate> | ||
+ | * <code>bold=yes</code> — <translate><!--T:117--> Keep bold text.</translate> | ||
+ | * <code>quote=yes</code> — <translate><!--T:102--> Wrap the excerpt with <tvar name=1>{{tag|blockquote|open}}</tvar> tags.</translate> | ||
+ | * <code>inline=yes</code> — <translate><!--T:103--> Remove the hatnote and <tvar name=1>{{tag|div|open}}</tvar> tags around the excerpt, to use it inside other text.</translate> | ||
+ | * <code>references=no</code> — <translate><!--T:104--> Remove all references.</translate> | ||
+ | * <code>subsections=yes</code> — <translate><!--T:105--> Include subsections of the transcluded section. Notice that if the transclusion is done from a section level 3, and the transcluded subsections are level 3 too, then the transcluded subsections will show with the same hierarchy as the transcluding section, which is probably not desirable, so use with caution.</translate> | ||
+ | |||
+ | <translate> | ||
+ | === Replacing sections for excerpts === <!--T:65--> | ||
+ | </translate> | ||
+ | [[File:How to excerpt.webm|thumb|<translate><!--T:66--> How to replace a section for an excerpt.</translate>]] | ||
+ | |||
+ | <translate><!--T:67--> Sections are often summaries of more precise subpages.</translate> | ||
+ | <translate><!--T:68--> Sometimes it's convenient to replace the content of such sections for excerpts of the subpages, after merging the original content of the section (if any) into the subpage.</translate> | ||
+ | <translate><!--T:69--> This improves both the subpage and the section, reduces maintenance, drives contributors to collaborate, etc.</translate> | ||
+ | |||
+ | <translate><!--T:70--> An efficient way to proceed is:</translate> | ||
+ | |||
+ | <translate> | ||
+ | <!--T:71--> | ||
+ | # Open the section in one tab and the subpage in another.</translate> | ||
+ | <translate> | ||
+ | <!--T:72--> | ||
+ | # Edit both.</translate> | ||
+ | <translate> | ||
+ | <!--T:73--> | ||
+ | # Copy the text of the section and paste it below the lead section of the subpage.</translate> | ||
+ | <translate> | ||
+ | <!--T:74--> | ||
+ | # Delete repeated content and adjust using common sense.</translate> | ||
+ | <translate> | ||
+ | <!--T:75--> | ||
+ | # Save the changes in the subpage with an edit summary like: Bring content from <tvar name=1><nowiki>[[Page]]</nowiki></tvar>.</translate> | ||
+ | <translate> | ||
+ | <!--T:76--> | ||
+ | # Back to the section, delete all content and replace it for an excerpt of the subpage.</translate> | ||
+ | <translate> | ||
+ | <!--T:77--> | ||
+ | # Save the changes in the section with an edit summary like: Move content to <tvar name=1><nowiki>[[Subpage]]</nowiki></tvar> and leave an excerpt. | ||
+ | |||
+ | == Examples == <!--T:78--> | ||
+ | |||
+ | === Lead section === <!--T:79--> | ||
+ | </translate> | ||
+ | <pre>{{Excerpt|Lorem ipsum}}</pre> | ||
+ | {{Excerpt|Lorem ipsum}} | ||
+ | {{Reflist}} | ||
+ | {{Clear}} | ||
+ | |||
+ | <translate> | ||
+ | === Specific section === <!--T:84--> | ||
+ | </translate> | ||
+ | <pre>{{Excerpt|Lorem ipsum|Section}}</pre> | ||
+ | {{Excerpt|Lorem ipsum|Section}} | ||
+ | |||
+ | <translate> | ||
+ | === Files only === <!--T:81--> | ||
+ | </translate> | ||
+ | <pre>{{Excerpt|Lorem ipsum|only=files|hat=no}}</pre> | ||
+ | {{Excerpt|Lorem ipsum|only=files|hat=no}} | ||
+ | {{Clear}} | ||
+ | |||
+ | <translate> | ||
+ | === Infobox only === <!--T:97--> | ||
+ | </translate> | ||
+ | <pre>{{Excerpt|Extension:CategoryLockdown|only=templates|templates=Extension|this=This infobox is}}</pre> | ||
+ | {{Excerpt|Extension:CategoryLockdown|only=templates|templates=Extension|this=This infobox is}} | ||
+ | {{Clear}} | ||
+ | |||
+ | <translate> | ||
+ | === No infobox === <!--T:98--> | ||
+ | </translate> | ||
+ | <pre>{{Excerpt|Extension:CategoryLockdown|templates=-Extension}}</pre> | ||
+ | {{Excerpt|Extension:CategoryLockdown|templates=-Extension}} | ||
+ | |||
+ | <translate> | ||
+ | === Portal === <!--T:85--> | ||
+ | </translate> | ||
+ | <pre>{{Excerpt|Lorem ipsum|files=1|references=no|hat=no|more=yes}}</pre> | ||
+ | {{Excerpt|Lorem ipsum|files=1|references=no|hat=no|more=yes}} | ||
+ | {{Clear}} | ||
+ | |||
+ | <translate> | ||
+ | == See also == <!--T:82--> | ||
+ | </translate> | ||
+ | * [[Module:Transcluder]] | ||
+ | * [[Module:Excerpt]] | ||
+ | * [[Module:Excerpt/config]] | ||
+ | * [[c:Data:I18n/Module:Excerpt.tab]] | ||
+ | |||
+ | <translate> | ||
+ | == Template data == <!--T:83--> | ||
+ | </translate> | ||
+ | {{#invoke:TNT|doc|Excerpt}} | ||
+ | |||
+ | }} | ||
+ | </noinclude> |
Revision as of 05:39, 26 November 2022
<languages />
This template uses Lua: |
<translate> This template is used for reusing parts of pages in other pages.</translate> <translate> This practice has several advantages:</translate>
<translate>
- Reduces maintenance by avoiding duplicate content that must be updated multiple times</translate>
<translate>
- Improves content quality by encouraging editors to merge related content, rather than having multiple versions in various stages of development</translate>
<translate>
- Fosters collaboration by channeling contributors into one place, rather than working in parallel
This template extends the capabilities of the built-in [[<tvar name=1>Special:MyLanguage/Transclusion</tvar>|normal transclusion]].
Usage
Basic usage
</translate>
{{Excerpt|Page title}}
— <translate> Transclude the lead section ([[<tvar name=1>#Lead section</tvar>|example]])</translate>{{Excerpt|Page title|Section title}}
— <translate> Transclude a specific section, excluding any subsections ([[<tvar name=1>#Specific section</tvar>|example]])</translate>
<translate>
Parameters
</translate>
1
— <translate> Title of the page to transclude.</translate> <translate> Only required parameter.</translate> <translate> By default the lead section will be transcluded ([[<tvar name=1>#Lead section</tvar>|example]]).</translate>2
— <translate> Title of the section to transclude ([[<tvar name=1>#Specific section</tvar>|example]]) or name of the [[<tvar name=2>Special:MyLanguage/Extension:Labeled Section Transclusion#How it works</tvar>|<tvar name=3><section>
</tvar> tag]] to transclude.</translate> <translate> Notice that this template provides other ways of targeting specific elements of a page without having to resort to section tags.</translate>only
— <translate> Elements to transclude ([[<tvar name=1>#Files only</tvar>|example]]).</translate> <translate> By default all elements are transcluded.</translate>only=file
<translate> or</translate>only=files
— <translate> Transclude only files</translate>only=list
<translate> or</translate>only=lists
— <translate> Transclude only lists</translate>only=table
<translate> or</translate>only=tables
— <translate> Transclude only tables</translate>only=template
<translate> or</translate>only=templates
— <translate> Transclude only templates</translate>only=paragraph
<translate> or</translate>only=paragraphs
— <translate> Transclude only paragraphs</translate>
paragraphs
— <translate> Paragraphs to transclude.</translate> <translate> By default all paragraphs are transcluded.</translate>paragraphs=0
— <translate> Transclude no paragraphs</translate>paragraphs=1
— <translate> Transclude the first paragraph</translate>paragraphs=2
— <translate> Transclude the second paragraph</translate>paragraphs=1,3
— <translate> Transclude the first and third paragraphs</translate>paragraphs=1-3
— <translate> Transclude the first, second and third paragraphs</translate>paragraphs=1-3,5
— <translate> Transclude the first, second, third and fifth paragraphs</translate>paragraphs=-1
— <translate> Transclude all paragraphs except the first</translate>paragraphs=-2
— <translate> Transclude all paragraphs except the second</translate>paragraphs=-1,3
— <translate> Transclude all paragraphs except the first and third</translate>paragraphs=-1-3
— <translate> Transclude all paragraphs except the first, second and third</translate>paragraphs=-1-3,5
— <translate> Transclude all paragraphs except the first, second, third and fifth</translate>
lists
— <translate> Lists to transclude.</translate> <translate> By default all lists are transcluded.</translate> <translate> Same syntax as when transcluding paragraphs.</translate>files
— <translate> Files to transclude.</translate> <translate> By default all files are transcluded.</translate> <translate> Same syntax as when transcluding paragraphs, but also:</translate>files=A.jpg
— <translate> Transclude the file named '<tvar name=1>A.jpg</tvar>'</translate>files=A.jpg, B.png, C.gif
— <translate> Transclude the files named '<tvar name=1>A.jpg</tvar>', '<tvar name=2>B.png</tvar>' and '<tvar name=3>C.gif</tvar>'</translate>files=.+%.png
— <translate> Transclude all PNG files</translate>files=-A.jpg
— <translate> Transclude all files except the one named '<tvar name=1>A.jpg</tvar>'</translate>files=-A.jpg, B.png, C.gif
— <translate> Transclude all files except the ones named '<tvar name=1>A.jpg</tvar>', '<tvar name=2>B.png</tvar>' and '<tvar name=3>C.gif</tvar>'</translate>files=-.+%.png
— <translate> Transclude all non-PNG files</translate>
tables
— <translate> Tables to transclude.</translate> <translate> By default all tables are transcluded.</translate> <translate> Same syntax as when transcluding paragraphs, but also:</translate>tables=Stats2020
— <translate> Transclude the table with id '<tvar name=1>Stats2020</tvar>'</translate>tables=Stats2020, Stats2019, Stats2018
— <translate> Transclude the tables with ids '<tvar name=1>Stats2020</tvar>', '<tvar name=2>Stats2019</tvar>' and '<tvar name=3>Stats2018</tvar>'</translate>tables=-Stats2020
— <translate> Transclude all tables except the one with id '<tvar name=1>Stats2020</tvar>'</translate>tables=-Stats2020, Stats2019, Stats2018
— <translate> Transclude all tables except the ones with ids '<tvar name=1>Stats2020</tvar>', '<tvar name=2>Stats2019</tvar>' and '<tvar name=3>Stats2018</tvar>'</translate>
templates
— <translate> Templates to transclude.</translate> <translate> By default all templates are transcluded.</translate> <translate> Same syntax as when transcluding paragraphs, but also:</translate>templates=Infobox
— <translate> Transclude the template '<tvar name=1>Infobox</tvar>'</translate>templates=Infobox, Navbox, Chart
— <translate> Transclude the template '<tvar name=1>Infobox</tvar>', '<tvar name=2>Navbox</tvar>' and '<tvar name=3>Chart</tvar>'</translate>templates=-Infobox
— <translate> Transclude all templates except '<tvar name=1>Infobox</tvar>'</translate>templates=-Infobox, Navbox, Chart
— <translate> Transclude all templates except '<tvar name=1>Infobox</tvar>', '<tvar name=2>Navbox</tvar>' and '<tvar name=3>Chart</tvar>'</translate>
this
— <translate> Change the initial text of the hatnote. For example, if the transcluded content is a gallery, you can set <tvar name=1>this=This gallery is
</tvar> so that the hatnote reads "This gallery is an excerpt from..."</translate>hat=no
— <translate> Hide the hatnote "This section is an excerpt from..."</translate>more=yes
— <translate> Show a "Read more..." link at the end</translate>bold=yes
— <translate> Keep bold text.</translate>quote=yes
— <translate> Wrap the excerpt with <tvar name=1><blockquote>
</tvar> tags.</translate>inline=yes
— <translate> Remove the hatnote and <tvar name=1><div>
</tvar> tags around the excerpt, to use it inside other text.</translate>references=no
— <translate> Remove all references.</translate>subsections=yes
— <translate> Include subsections of the transcluded section. Notice that if the transclusion is done from a section level 3, and the transcluded subsections are level 3 too, then the transcluded subsections will show with the same hierarchy as the transcluding section, which is probably not desirable, so use with caution.</translate>
<translate>
Replacing sections for excerpts
</translate> File:How to excerpt.webm
<translate> Sections are often summaries of more precise subpages.</translate> <translate> Sometimes it's convenient to replace the content of such sections for excerpts of the subpages, after merging the original content of the section (if any) into the subpage.</translate> <translate> This improves both the subpage and the section, reduces maintenance, drives contributors to collaborate, etc.</translate>
<translate> An efficient way to proceed is:</translate>
<translate>
- Open the section in one tab and the subpage in another.</translate>
<translate>
- Edit both.</translate>
<translate>
- Copy the text of the section and paste it below the lead section of the subpage.</translate>
<translate>
- Delete repeated content and adjust using common sense.</translate>
<translate>
- Save the changes in the subpage with an edit summary like: Bring content from <tvar name=1>[[Page]]</tvar>.</translate>
<translate>
- Back to the section, delete all content and replace it for an excerpt of the subpage.</translate>
<translate>
- Save the changes in the section with an edit summary like: Move content to <tvar name=1>[[Subpage]]</tvar> and leave an excerpt.
Examples
Lead section
</translate>
{{Excerpt|Lorem ipsum}}
Template:Reflist Template:Clear
<translate>
Specific section
</translate>
{{Excerpt|Lorem ipsum|Section}}
<translate>
Files only
</translate>
{{Excerpt|Lorem ipsum|only=files|hat=no}}
<translate>
Infobox only
</translate>
{{Excerpt|Extension:CategoryLockdown|only=templates|templates=Extension|this=This infobox is}}
<translate>
No infobox
</translate>
{{Excerpt|Extension:CategoryLockdown|templates=-Extension}}
<translate>
Portal
</translate>
{{Excerpt|Lorem ipsum|files=1|references=no|hat=no|more=yes}}
<translate>
See also
</translate>
<translate>
Template data
</translate> Lua error in Module:TNT at line 124: mw.text.jsonEncode: Cannot use type 'boolean' as a table key.