== Transclusione ==
Una transclusione è generalmente l'inclusione del contenuto di un documento in un altro, come riferimento. In un contesto wiki, è l'uso della funzionalità template di MediaWiki per includere lo stesso contenuto in più documenti, senza dover modificare tali documenti separatamente.
Come funziona la transclusione
Per transcludere qualsiasi pagina sorgente (all'interno di un singolo progetto MediaWiki, come Wikipedia) all'interno di un'altra pagina destinazione, inserire il seguente codice: {{UNAPAGINA}}
Ogni volta che la pagina di destinazione A viene resa, l'intero contenuto della pagina di origine B (in questo caso, UNAPAGINA) verrà inserita nel punto in cui è stato inserito il tag di transclusione.
Ad esempio, potresti decidere di inserire un messaggio di benvenuto nella pagina di discussione di ogni nuovo arrivato. La transclusione crea un collegamento "live" tra la pagina modello (template) e la/le pagina/e di destinazione su cui il messaggio dovrebbe apparire. Quando il modello viene modificato, vengono modificate anche tutte le pagine di destinazione.
Potresti anche decidere di creare una pagina (modello/template) con il tuo indirizzo postale e includere quel modello non solo sulla tua pagina, ma anche su tutte le pagine dei tuoi amici. Quando traslochi in un altro appartamento, puoi cambiare il modello di indirizzo e le nuove informazioni verranno automaticamente aggiornate su tutte le pagine degli amici.
Markup e sintassi di transclusione
Se la fonte è nel namespace Template (ad esempio "Template:Welcome"), basta usare il nome stesso, da solo:
{{Welcome}}
Se la fonte è nel namespace principale (ad esempio "VisualEditor"), deve essere aggiunto un due punti (:) davanti al nome:
{{:VisualEditor}}
Se la fonte è in qualsiasi altro namespace (ad esempio "User:Example"), è necessario utilizzare il nome completo, compreso il namespace:
{{User:Example}}
Se l'origine è una sottopagina della pagina di destinazione, (ad esempio "Transclusion/ja"), puoi semplicemente specificare il nome della sottopagina senza curarti del namespace:
{{/ja}}
Etimologia
Ted Nelson ha coniato il termine "== Transclusione == ", così come "ipertesto" e "Ipermedia", nel suo libro del 1982 Literary Machines .
Transclusione parziale
Utilizzando il markup "noinclude", "onlyinclude" e "includeonly", è possibile transcludere parte di una pagina piuttosto che tutta. Tali transclusioni parziali possono essere ottenute anche transcludendo da altre pagine, come le sottopagine. È spesso opportuno non transcludere alcune informazioni, come la documentazione del template e le categorie.
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
- Aiuto:Parole magiche
- Extension:Interwiki
Modelli
- Aiuto:Template
- Help:Substitution – another way to invoke templates
Usage on Wikimedia sites
- T6547 – Cross-Wikimedia inclusion (interwiki templates transclusion, etc.) unsupported