Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Help:Labeled section transclusion

From Wikipedia, the free encyclopedia
Wikipedia help page
Further information:Help:Transclusion § Selective transclusion, andExtension:Labeled Section Transclusion
This help page is ahow-to guide.
It explains concepts or processes used by the Wikipedia community. It is not one ofWikipedia's policies or guidelines, and may reflect varying levels ofconsensus.

Labeled Section Transclusion (LST) is aparser function that provides two ways for designating a "section" of a page fortransclusion. The first method identifies the section by using thepage name and aheading (thesection title as it appears in the source page). The second method allows the selection of an arbitrary "section" for transclusion, but this approach requires adding specificmarkup tolabel the desired section beforehand.

Three functions can transclude a section from a given page name.

  • {{#section:page name|label}} (a labeled section)
  • {{#section-x:page name|label}} (all except that labeled section)
  • {{#section-h:page name|heading}} (a normal section)

Note that there are also equivalent names for these functions, the base names being#lst,#lstx, and#lsth.

To prepare an arbitrary "section" for a labeled section transclusion, mark it withbegin andend attributes inside<section /> tags that contain yourlabel:

<section begin=label /> and<section end=label />

Compared to LST transclusion,partial transclusion markup cannot belabeled, and thus the source page cannot have one set of its sections transcluded to one page while having also a different set for another page. A page marked up with partial transclusion tags only, will always transclude the same. But LST and partial transclusion can work together on the same page.

These LST functions take additional parameters, as explained below.§ Example pages provides search links for the articles that currently employ LST so you can see how they are using it.

It would likely be beneficial for future editors of the page, especially if they edit in Visual Editor and are unfamiliar with wikitext, to leave a comment stating why the tags are there and to kindly not tamper with them or remove them:

<!-- *** PLEASE DO NOT REMOVE [[Help:Labeled section transclusion]]: ***<section> tags transclude the wikitext inside them to other article(s) live.These tags must please not be tampered with.You may freely edit the text between the tags.Transclusion target: [[Page name]]. --><sectionbegin=label/>Example wikitext.<sectionend=label/>

Functions summary

[edit]

This section summarizes the three parser functions in the Labeled Section Transclusion extension.


Syntax: {{function:fullpagename |section |range/change}}

ParameterParsing entity it identifies
1FullpagenameSource page. The only required argument. Type it in, or usevariables like {{FULLPAGENAME}}, (but notsubpage linking with../).
2SectionLabel ("labeled section"), orheading (section title), to transclude. Optional parameter. If a label, it must have been added and saved first.
3RangeFinal section in a contiguous series of headings or labels to transclude. Optional.
  • #section transcludes the final section.
  • #section-h does not transclude the final section.
  • #section-x does not take a range.
3ChangeReplacement wikitext. Only#lstx can rewrite a labeled section during transclusion. Optional.

It is not possible to passtemplate parameters to the transcluded section or page but the code of the page can usemagic words like{{PAGENAME}} to test where it is and behave differently.


Behaviors
Parser FunctionAliasDescription
#lst#sectionTransclude alabel found inside<section /> tags. Honors transclusion tags. Default is entire page. If the label is not found, transclude nothing.
#lstx#section-xTransclude entire page, butexclude a label. Blind to headings. Honors transclusion tags. Default is entire page. If the label is not found, transclude entire page.
#lsth#section-hTransclude aheading (section title). Blind to labels.Does not honor transclusion tags. Defaults to the lead section. If the heading is not found, transclude nothing.
  #section-h makes its target look the same as its source. On thesource page
  • <noinclude> displays its content
  • <onlyinclude> displays its content
  • <includeonly>does not display its content
So#section-h must not render<includeonly> content on thetarget page.


LST<section /> tags behavior:

  • Theend tag is not required. When only abegin tag is found, it goes to the end of the page.
  • The same label can mark severalbegin/end sections. A range is then everything from the firstbegin to lastend.
  • Different labels can overlap. They can also nest.
  • Cannot be placed by a transclusion, but instead must be present on the page as saved in the database. See§ No template below.

LST transclusion options:

Standard syntax applies:

  • Generous whitespace is allowed:{{ #lst:  namespace:  pagename  |  section  }}
  • An unspaced : colon follows the parser function name.
  • In tags no spaces around the = sign of the label (attribute):begin=label
  • In tags space is optional before the / slash:<section end=label />

Common usage errors.

Markup

[edit]

No markup of the source page is needed if only section titles are used to specify the transclusion. This is the case with#section-h.

For labeling a section for LST transclusion use the following markup.

Section marking

[edit]

Markup your section boundaries in the source page using two, singular,<section /> tags; for example, to label a section "chapter1":

<section begin=chapter1 />this is a chapter<section end=chapter1 />

Note this is not normal opening-tag, closing-tag HTML. In HTML<section>...</section> is invalid. This parser tag,<section />, is incompatible with an HTML element because MediaWiki markup employs a unique parser tag, added just for the Labeled Section Transclusion extension.

Section transclusion

[edit]

Use the parser function#section to transclude the section. For example, to transclude section labeledchapter1 from a page calledarticleX:

{{#section:ArticleX|chapter1}}

Transclude the page but exclude the section

[edit]

To transclude a page, but exclude a specified section, use the#section-x parser function:

{{#section-x:fullpagename|label}}

or

{{#section-x:fullpagename|heading}}

Optionally, you may add replacement text to the excluded section.

{{#section-x:fullpagename|label|replacement text}}

Example:

{{#section-x:articleX|chapter1|See chapter 1 in[[articleX]].}}

The replacement text will appear in the area where the section is skipped (excluded).

Dealing with stray whitespace

[edit]

By default,#section will include all the whitespace in the section, which can lead to issues if you're trying to transclude the section into a different article. To solve this, make use of the fact that the {{#if}} parser function trims its inputs, e.g.

{{#if:1|{{#section:ArticleX|chapter1}}}}

This will get rid of both leading and trailing whitespace, and the article will render as intended. Because you are nesting templates, it will double thepost-expand include size of the excerpt, which can present a problem on longer pages, so you may wish to edit the source page to wrap the content you want to include, without the whitespace, in<onlyinclude>...</onlyinclude> tags instead. You can also use the{{trim}} template instead of {{#if:1}}, but because it is just a wrapper for the {{#if:1}} technique above, it results in a tripling of the post-expand include size.

Other functions

[edit]

Discontiguous sections

[edit]

It is possible to have multiple sections with the same name; in this case, every section with that name will be included/excluded. This is especially useful to mark various discussions.

Section ranges

[edit]

These functions can transclude the whole page, so they have the two, optional argument to specify behaviours: 1) a name-tagged section or heading-title, 2) a range of such named section-tags or section titles, and 3) replacement content for a named section.

  • {{#section:articleX|chapter1|chapter3}} includes everything from the beginning of chapter 1 to the end of chapter 3. This allows using empty marker pairs to mark one end of the section, possibly in a template.
  • {{#section-h:articleX|chapter1|chapter3}} includes content of chapter1, heading and content of chapter 2.
  • {{#section-x:articleX|chapter1|chapter3}} replaces chapter1 heading and content with the word "chapter3".

Substitution

[edit]

Instead of transcluding every time, to "transclude" once (to copy), usesubstitution:

{{subst:#section...}}

For example to archive oldtalk on your talk page, you can copy it to an archive page, then delete it, all using LST:

  1. Put<section begin=archive /> at the beginning of the section you want to archive and<section end=archive /> at the end. (We use "archive" for the label, but any label will do.). This section can be anywhere, and it can be multiple sections.
  2. Save those change to your talk page.
  3. Create a new archive page. Put{{subst:#section:User talk:pagename|archive}}.
  4. Save that archive page. The old talk is copied over to it. The transclusion disappears because it was substituted.
  5. Edit your talk page again. Replace all the wikitext on the entire page with{{subst:#section-x:User talk:username|archive}}. Thedatabase page will be transcluded, minus the exact same wikitext in the saved archive, and minus the section tags (which we had labeled "archive").

When using substitution to transclude content on Wikipedia, please use the edit summary to applyreusers' rights and obligations. This applies to any substantial content, and not just article contents.

No template

[edit]

Currently, no template can facilitate this LST markup because it is necessary to use #tag in order to "preSaveTransform" magic words inside a tag of any kind. For the proper attempt see (the non-functioning){{section}}.

The only way toevaluate template argumentsinside a tag (because of the parsing order) is#tag. LST would need (template) evaluation of the label as the section tag is generated:

{{#tag: section|{{{1}}}}}

But #tag only producesXML-like (balanced, open-closed, start-end, pairs of) tags, while LST will use a singular, explicitly self closing, tag. So LST tags cannot be generated by any template. Compare actual (only in effect) output:

{{#tag:section|content|begin=label}} →<section begin=label>content</section>☒N
Tracked inPhabricator
Task T39256

with the requested output:

<section begin=label/>content <section end=label/>

Example pages

[edit]

These aresearches stored in a link:

See also

[edit]

Templates

[edit]
  • {{Excerpt}}
  • {{Section transclude}}
  • {{R}} - a referencing/citation template optionally taking advange of labeled section transclusion to mark context sections
General
technical help
Special
page
-related
Wikitext
Links anddiffs
Media files: images,
videos and sounds
Other graphics
Templates and
Lua modules
Data structure
HTML andCSS
Customisation
and tools
Automated editing
Retrieved from "https://en.wikipedia.org/w/index.php?title=Help:Labeled_section_transclusion&oldid=1318135671"
Categories:

[8]ページ先頭

©2009-2025 Movatter.jp