Help:Labeled section transclusion

Labeled Section Transclusion (LST) offers two basic ways to specify a "section" of a page for transclusion. One way uses the page name and a heading (section title, as seen on the rendered page). The other way enables an arbitrary "section" for transclusion, but it requires markup first in order to add the label.

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,  , and.

To prepare an arbitrary "section" for a labeled section transclusion, mark it with begin and end attributes inside tags that contain your label:
 * single and single

Compared to LST transclusion, partial transclusion markup cannot be labeled, 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. provides search links for the articles that currently employ LST so you can see how they are using it.

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

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

It is not possible to pass template parameters to the transcluded section or page but the code of the page can use magic words like  to test where it is and behave differently.


 * &dagger;    #section-h makes its target look the same as its source. On the source page
 * &lt;noinclude> displays its content
 * &lt;onlyinclude> displays its content
 * &lt;includeonly > does not display its content
 * So #section-h must not render content on the target page.

LST s tags behavior:
 * The end tag is not required. When only a begin tag is found, it goes to the end of the page.
 * The same label can mark several begin/end sections. A range is then everything from the first begin to last end.
 * 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 below.

LST transclusion options:
 * It can be previewed.
 * The target page can be the source page itself.
 * It can be substituted. See  below.

Standard syntax applies:
 * Generous whitespace is allowed: { {   #lst:    namespace:    pagename
 * 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: &lt;section end=label />

Common usage errors.
 * Template loop detected: preview transcluding a transclusion in the saved version?
 * Cite errors. You must have the full definition of a named reference on any page that this List-defined reference () is needed.
 * To render transcluding footnotes, you must tag where they go on the page.

Markup
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
Markup your section boundaries in the source page using two, singular, s tags; for example, to label a section "chapter1":

this is a chapter

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

Section transclusion
Use the parser function  to transclude the section. For example, to transclude section labeled chapter1 from a page called articleX:

Transclude the page but exclude the section
To transclude a page, but exclude a specified section, use the  parser function:

or

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

Example:

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

Dealing with stray whitespace
By default,  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 parser function trims its inputs, e.g.

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 the post-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  tags instead. You can also use the trim template instead of, but because it is just a wrapper for the technique above, it results in a tripling of the post-expand include size.

Discontiguous sections
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
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.
 * 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.
 * includes content of chapter1, heading and content of chapter 2.
 * replaces chapter1 heading and content with the word "chapter3".

Substitution
Instead of transcluding every time, to "transclude" once (to copy), use substitution:
 * { {subst: #section...}}

For example to archive old talk on your talk page, you can copy it to an archive page, then delete it, all using LST:
 * 1) Put  at the beginning of the section you want to archive and  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}} .  The database 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 apply reusers' rights and obligations. This applies to any substantial content, and not just article contents.

No template
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 to evaluate template arguments inside a tag (because of the parsing order) is #tag. LST would need (template) evaluation of the label as the section tag is generated:

But #tag only produces XML-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} } &rarr; &lt;section begin=label> content &lt;/section>

with the requested output:

&lt;section begin=label /> content &lt;section end=label />

Example pages
These are searches stored in a link:
 * (Articles)
 * {{sl|insource:section insource:/\{\{\#section/}} (Articles)
 * {{sl|all: insource:"section x" insource:/\#"section-x"/}} (entire wiki)
 * {{sl|insource:lst insource:/\#lst/}} (Articles)
 * {{sl|insource:lsth insource:/\{\{\#lsth/}} (Articles)
 * {{sl|all: insource:lstx insource:/\#lstx/}} (entire wiki)

Templates

 * Excerpt
 * Section transclude
 * R - a referencing/citation template optionally taking advange of labeled section transclusion to mark context sections