Différences entre versions de « Help/Transclusion »
Ligne 1 : | Ligne 1 : | ||
'''Transclusion''' is the inclusion of the content of a document into another document by reference. Beyond template transclusion, it is particularly useful in full text division in [[Help/Texts#Full_text_divided_into_multiple_parts|multiple parts]] and [[Help/Annotations along the text|annotations along the text]]. | '''Transclusion''' is the inclusion of the content of a document into another document by reference. Beyond template transclusion, it is particularly useful in full text division in [[Help/Texts#Full_text_divided_into_multiple_parts|multiple parts]] and [[Help/Annotations along the text|annotations along the text]]. | ||
− | + | ===Syntax=== | |
If the source is a template, just use the name itself, alone: | If the source is a template, just use the name itself, alone: | ||
* <code><nowiki>{{Infobox-fr}}</nowiki></code> or <code><nowiki>{{Infobox-hu}}</nowiki></code> (See [[Help/Texts|Texts]] and [[Help/Authors|Authors]]) | * <code><nowiki>{{Infobox-fr}}</nowiki></code> or <code><nowiki>{{Infobox-hu}}</nowiki></code> (See [[Help/Texts|Texts]] and [[Help/Authors|Authors]]) | ||
Ligne 8 : | Ligne 8 : | ||
If the source is in not a template, a colon (<code>:</code>) must be added in front of the name. This is the case when you assemble [[Help/Texts#Full_text_divided_into_multiple_parts|multiple parts]] of a full text into one page. For example, the page [[Du côté de chez Swann/Texte intégral]] assembles ([[#Partial transclusion|partially]]) three pages: <nowiki>{{Du côté de chez Swann/Partie 1}}, {{Du côté de chez Swann/Partie 2}} and {{Du côté de chez Swann/Partie 3}}</nowiki>. | If the source is in not a template, a colon (<code>:</code>) must be added in front of the name. This is the case when you assemble [[Help/Texts#Full_text_divided_into_multiple_parts|multiple parts]] of a full text into one page. For example, the page [[Du côté de chez Swann/Texte intégral]] assembles ([[#Partial transclusion|partially]]) three pages: <nowiki>{{Du côté de chez Swann/Partie 1}}, {{Du côté de chez Swann/Partie 2}} and {{Du côté de chez Swann/Partie 3}}</nowiki>. | ||
− | + | ||
+ | ===Partial transclusion=== | ||
By using "noinclude", "onlyinclude" and "includeonly" markup, it is possible to transclude part of a page rather than all of it. Such partial transclusions can also be achieved by transcluding from other pages such as subpages. It is often desirable not to transclude some information, such as categories. | By using "noinclude", "onlyinclude" and "includeonly" markup, it is possible to transclude part of a page rather than all of it. Such partial transclusions can also be achieved by transcluding from other pages such as subpages. It is often desirable not to transclude some information, such as categories. | ||
− | + | ====Transclusion markup==== | |
* '''noinclude''' - The markup <code><nowiki><noinclude>...</noinclude></nowiki></code> means that the text between the tags ''will not be transcluded onto another page and will appear only on the page itself''. This is useful for [[Help/Categories|categories]] and [[Help/Interlanguage links|interlanguage links]]. | * '''noinclude''' - The markup <code><nowiki><noinclude>...</noinclude></nowiki></code> means that the text between the tags ''will not be transcluded onto another page and will appear only on the page itself''. This is useful for [[Help/Categories|categories]] and [[Help/Interlanguage links|interlanguage links]]. | ||
* '''includeonly''' - The markup <code><nowiki><includeonly>...</includeonly></nowiki></code> means that the text between the tags ''will only be used when the page is transcluded onto another page, and will not appear on the page itself''. | * '''includeonly''' - The markup <code><nowiki><includeonly>...</includeonly></nowiki></code> means that the text between the tags ''will only be used when the page is transcluded onto another page, and will not appear on the page itself''. | ||
Ligne 17 : | Ligne 18 : | ||
For example, [[Du côté de chez Swann/Texte intégral]] partially transcludes three pages. The <code><nowiki><div></nowiki></code> block on the top of each part ("Du côté de chez Swann/Partie 1", "Du côté de chez Swann/Partie 2", "Du côté de chez Swann/Partie 3"), containing basic information about the text, is between <code><nowiki><noinclude></nowiki></code> tags, and a <code><nowiki><div></nowiki></code> block, with relevant information about the whole text, is on the top of the full text page, before transclusion tags. | For example, [[Du côté de chez Swann/Texte intégral]] partially transcludes three pages. The <code><nowiki><div></nowiki></code> block on the top of each part ("Du côté de chez Swann/Partie 1", "Du côté de chez Swann/Partie 2", "Du côté de chez Swann/Partie 3"), containing basic information about the text, is between <code><nowiki><noinclude></nowiki></code> tags, and a <code><nowiki><div></nowiki></code> block, with relevant information about the whole text, is on the top of the full text page, before transclusion tags. | ||
+ | |||
+ | |||
+ | ===Labeled section transclusion=== | ||
+ | The '''Labeled section transclusion''' allows selective transclusion of marked-off sections of text. Its functionality is similar to an enhanced version of the <code><nowiki><onlyinclude></nowiki></code> tag with normal transclusion, which selects sections for inclusion. | ||
+ | |||
+ | While normal transclusion is primarily intended to transclude large portions of small templates, labeled section transclusion is intended for small portions of large pages. | ||
+ | |||
+ | However, there are some differences. In the native transclusion, sections are marked by behavior; thus you can have only one (possibly non-contiguous) section to be included or skipped. | ||
+ | |||
+ | Here, sections are marked by name, and behavior is chosen by the caller, which can include or skip sections as needed. Different pages can include or exclude selected sections; there can be arbitrary numbers of sections, which can also overlap arbitrarily. | ||
+ | |||
+ | Marking sections by name rather than behavior allows edit section links to be rendered more appropriately for getting excerpts from larger texts, since the extension can now account for sections that are skipped in the beginning of the page, allowing transcluded sections to be offset appropriately. | ||
+ | |||
+ | ====How it works==== | ||
+ | '''Step 1: Mark off sections'''<br> | ||
+ | Mark off sections in the text using <code><nowiki><section></nowiki></code> tags like this: | ||
+ | <pre> | ||
+ | <section begin=chapter1 />this is a chapter 1<section end=chapter1 /> | ||
+ | </pre> | ||
+ | Note that these tags are not HTML/XML, and do not use the normal attribute syntax. For this reason, and because the begin and end markers are individual, rather than normal XML open/close tags, this allows nested or overlapping sections. This allows you to insert section tags without worrying about interfering with other sections. | ||
+ | |||
+ | '''Step 2a: Transclude the section'''<br> | ||
+ | Call the parser function <code>#lst</code> to transclude it, i.e. to transclude a section called ''chapter1'' from a page called ''articleX'': | ||
+ | <pre> | ||
+ | {{#lst:articleX|chapter1}} | ||
+ | </pre> | ||
+ | The target article defines the location of the section; its behavior is determined by the parser function. | ||
+ | |||
+ | '''Step 2b: Transclude the page but excluding the section'''<br> | ||
+ | |||
Version du 3 novembre 2020 à 14:14
Transclusion is the inclusion of the content of a document into another document by reference. Beyond template transclusion, it is particularly useful in full text division in multiple parts and annotations along the text.
Syntax
If the source is a template, just use the name itself, alone:
{{Infobox-fr}}
or{{Infobox-hu}}
(See Texts and Authors){{Image}}
(See Image pages)
If the source is in not a template, a colon (:
) must be added in front of the name. This is the case when you assemble multiple parts of a full text into one page. For example, the page Du côté de chez Swann/Texte intégral assembles (partially) three pages: {{Du côté de chez Swann/Partie 1}}, {{Du côté de chez Swann/Partie 2}} and {{Du côté de chez Swann/Partie 3}}.
Partial transclusion
By using "noinclude", "onlyinclude" and "includeonly" markup, it is possible to transclude part of a page rather than all of it. Such partial transclusions can also be achieved by transcluding from other pages such as subpages. It is often desirable not to transclude some information, such as categories.
Transclusion markup
- noinclude - The markup
<noinclude>...</noinclude>
means that the text between the tags will not be transcluded onto another page and will appear only on the page itself. This is useful for categories and interlanguage links. - includeonly - The markup
<includeonly>...</includeonly>
means that the text between the tags will only be used when the page is transcluded onto another page, and will not appear on the page itself. - onlyinclude - The markup
<onlyinclude>...</onlyinclude>
indicates that only text surrounded by "onlyinclude" markup should be transcluded onto another page, but will appear on the page itself if not accompanied by "includeonly" tags as well. This is the most subtle of the partial transclusion tags because it often overrules the others. If there is at least one pair of "onlyinclude" tags on a page, then whenever this page is transcluded, it is only the material within the "onlyinclude" tags which gets transcluded. There can be several such sections, and within each such section, some material might be further excluded by "noinclude" tags, and might also be surrounded by "includeonly" tags so that it does not appear on the original page itself. But material outside the "onlyinclude" tags will be ignored when the page is transcluded onto another page. This can be useful, for example, to repeat a small part of one page on a second one: just surround the small part by onlyinclude tags, and transclude it onto the second page. Note that unlike<noinclude>
and<includeonly>
,<onlyinclude>
will take precedence over enclosing<nowiki>
tags. In other words,<nowiki> <onlyinclude>My content</onlyinclude> </nowiki>
produces only "My content" when transcluded.
For example, Du côté de chez Swann/Texte intégral partially transcludes three pages. The <div>
block on the top of each part ("Du côté de chez Swann/Partie 1", "Du côté de chez Swann/Partie 2", "Du côté de chez Swann/Partie 3"), containing basic information about the text, is between <noinclude>
tags, and a <div>
block, with relevant information about the whole text, is on the top of the full text page, before transclusion tags.
Labeled section transclusion
The Labeled section transclusion allows selective transclusion of marked-off sections of text. Its functionality is similar to an enhanced version of the <onlyinclude>
tag with normal transclusion, which selects sections for inclusion.
While normal transclusion is primarily intended to transclude large portions of small templates, labeled section transclusion is intended for small portions of large pages.
However, there are some differences. In the native transclusion, sections are marked by behavior; thus you can have only one (possibly non-contiguous) section to be included or skipped.
Here, sections are marked by name, and behavior is chosen by the caller, which can include or skip sections as needed. Different pages can include or exclude selected sections; there can be arbitrary numbers of sections, which can also overlap arbitrarily.
Marking sections by name rather than behavior allows edit section links to be rendered more appropriately for getting excerpts from larger texts, since the extension can now account for sections that are skipped in the beginning of the page, allowing transcluded sections to be offset appropriately.
How it works
Step 1: Mark off sections
Mark off sections in the text using <section>
tags like this:
<section begin=chapter1 />this is a chapter 1<section end=chapter1 />
Note that these tags are not HTML/XML, and do not use the normal attribute syntax. For this reason, and because the begin and end markers are individual, rather than normal XML open/close tags, this allows nested or overlapping sections. This allows you to insert section tags without worrying about interfering with other sections.
Step 2a: Transclude the section
Call the parser function #lst
to transclude it, i.e. to transclude a section called chapter1 from a page called articleX:
{{#lst:articleX|chapter1}}
The target article defines the location of the section; its behavior is determined by the parser function.
Step 2b: Transclude the page but excluding the section