Transclusió
La transclusió és generalment la inclusió del contingut d'un document en un altre document per referència. En un context wiki, és l'ús de la funcionalitat de plantilla de MediaWiki per incloure el mateix contingut en diversos documents sense haver d'editar aquests documents per separat.
Com funciona la transclusió
Per transcloure qualsevol pàgina d'origen (dins d'un sol projecte MediaWiki, com ara la Viquipèdia) dins d'una altra pàgina de destinació.
Per exemple, havent creat prèviament la pàgina "Plantilla:Pàgina_a_transcloure", amb contingut, incloeu el codi {{Pàgina_a_transcloure}} a la pàgina de destinació.
Sempre que es renderitzi la pàgina de destinació A, tot el contingut de la pàgina d'origen B (en aquest cas, Pàgina_a_transcloure) es renderitza a la ubicació on es va col·locar l'etiqueta de transclusió.
Per exemple, podeu decidir col·locar un missatge de benvinguda a la pàgina de discussió de cada nouvingut. La transclusió crea un enllaç "en directe" entre la pàgina de plantilla i la pàgina o pàgines de destinació on hauria d'aparèixer el missatge. Quan s'edita la plantilla, també s'editen totes les pàgines de destinació.
També podeu decidir crear una pàgina (una plantilla) amb la vostra adreça postal i incloure aquesta plantilla no només a la vostra pàgina, sinó també a totes les pàgines dels vostres amics. Quan us canvieu a una altra casa, podeu canviar en la plantilla l'adreça i aquesta nova informació s'actualitzarà automàticament a totes les pàgines dels vostres amics.
Transclusion Markup & Syntax
If the source is in the Template namespace (e.g. "Template:Welcome"), just use the name itself, alone:
{{Welcome}}
If the source is in the Main article namespace (e.g. "VisualEditor"), a colon (:) must be added in front of the name:
{{:VisualEditor}}
If the source is in any other namespace (e.g. "User:Example"), you must use the full name, including the namespace:
{{User:Example}}
If the source is a subpage of the target page, (e.g. "Transclusion/ja"), you can simply specify the name of the subpage regardless of namespace:
{{/ja}}
Etymology
Ted Nelson coined the term "Transclusió ", as well as "hypertext" and "hypermedia", in his 1982 book Literary Machines .
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 template documentation and categories.
Examples of when to use full versus partial transclusion
Use full transclusion when you want to include the full content of a source page in a target page. For example, you could include the full content of a page about apples in a page about tree fruits. Use partial transclusion when you only want to include part of a source page in a target page. For example, you could include only information about Granny Smith apples from a page about apples in a page about ingredients commonly used in baking.
Partial transclusion markup
- noinclude – The markup
<noinclude>...</noinclude>means that the text between the tags is visible exclusively on the source page and cannot be transcluded onto another page. This is useful for template documentation and categories. - includeonly – The markup
<includeonly>...</includeonly>means that the text between the tags will be hidden on the source page and visible only when transcluded onto a different page. This can be useful, for example, for adding categories to pages transcluding a template, without adding the template itself to these categories. - onlyinclude – The markup
<onlyinclude>...</onlyinclude>means that the text between the tags will be visible on the source page and visible when transcluded onto a different page. 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 that is transcluded. There can be several such "onlyinclude" sections on a 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.
<noinclude>, <includeonly>, and <onlyinclude> behave differently inside <nowiki> tags. nowiki tags enable escaping special markup, and does this for <noinclude> and <includeonly> tags. However, <onlyinclude> tags within <nowiki> tags produces only the content inside the <onlyinclude> tag.| Markup | Output when transcluded |
|---|---|
<nowiki><noinclude> My content </noinclude></nowiki>
|
<noinclude> My content </noinclude>
|
<nowiki><includeonly> My content </includeonly></nowiki>
|
<includeonly> My content </includeonly>
|
<nowiki><onlyinclude>My content</onlyinclude></nowiki>
|
My content |
You can nest all three transclusion types within each other, which enables you to refine exactly what content is displayed on the current page and is visible on transcluded pages.
Subpages
You can cut and paste the text to be transcluded into a subpage, then use the name of the subpage in the transclusion template. This approach can be used only where subpages are enabled; for example, on the English Wikipedia, subpages can be used only from User, Talk or Wikipedia pages; currently, subpages cannot be created from main article pages.
Example: you want to discuss the deletion and redirecting of Pussycat to Cat. First, create the subpage Talk:Pussycat/Let's delete Pussycat!, write your comment into it, then transclude it in Talk:Pussycat and Talk:Cat using the template {{Talk:Pussycat/Let's delete Pussycat!}}. Comments posted in either talk page will be shown in both.
Special pages
Some pages on Special:Specialpages can be transcluded, e.g.:
- Special:AllPages
- Special:ApiHelp
- Special:Contribute
- Special:Contributions
- Special:ListFiles
- Special:ListUsers
- Special:NewFiles
- Special:NewPages
- Special:PrefixIndex
- Special:RecentChanges
- Special:RecentChangesLinked
- Special:WantedPages
Sample: {{Special:Newpages/3}} gives 3 new pages.
URL parameters can be given like template parameters, e.g. {{Special:RecentChanges|namespace=10|limit=5}}
Alternatives to transclusion by template
Occasionally you may want to use a template, but for one reason or another may not want to use transclusion. The automatic one-time copying of a template's code/text to the location of a template tag is called Template substitution or subclusion (substitution + transclusion). To subclude a template's code/text, the template tag is modified from the standard transclusion tag to a substitution tag, simply by adding subst:, creating a tag with the form: {{subst:template name}}.
Labeled Section Transclusion
An extension called Labeled Section Transclusion enables marked sections of text to be transcluded.
Scribunto
You can transclude page content, or even parts of it, using Lua with the Scribunto extension. See Module:Transcluder for an example on this wiki.
Semantic MediaWiki
The Semantic MediaWiki extension uses inline queries to query and display semantic data. There are currently two ways to perform transclusion or something similar:
- Transclusion proper. The display format "embedded" ensures that selected pages (mainspace articles, templates, etc.) are transcluded. As with templates, sections placed between noinclude tags will be omitted.
- Selected passages in a page can be assigned a property of type 'Text'. These selections can be requested by running an inline query for this type of property.
See inline queries for further information.
See also
- w:Help:Transclusion
- T31051 – No support for versioned transclusions (specific page/template revisions)
- Extension:Labeled Section Transclusion
- Ajuda:Paraules màgiques
- Extension:Interwiki
Templates
- Ajuda:Plantilles
- Ajuda:Substitució – another way to invoke templates
Usage on Wikimedia sites
- T6547 – Cross-Wikimedia inclusion (interwiki templates transclusion, etc.) unsupported