Entertainment
 

Aiuto:Template

Da Memory Alpha.

Aiuto  Contenuti → Template

Il software MediaWiki ti consente di sostituire automaticamente messaggi ricorrenti o di uso frequente con dei modelli predefiniti chiamati Template da inserire nel testo dell'articolo. I Template hanno il loro proprio namespace all'interno del database, ed è per questo che le pagine contenenti i "modelli" iniziano tipicamente con il prefisso Template:.

Indice

[modifica] Includere un messaggio

La sintassi per inserire un messaggio predefinito, dal nome "Template:nome" è

{{nome}}

Questo riferimento nel linguaggio wikitext produce l'inserimento del contenuto del template, una volta salvata la pagina che lo contiene.

Se la pagina "Template:nome" non esiste, allora {{nome}} funzionerà come [[Template:nome]], un link ad una pagina inesistente, che porta alla relativa pagina di modifica.

I link ricorsivi, cioè che puntano a se stessi, non sono un problema, in tal caso infatti il risultato dell'auto-link produce un testo in grassetto, e non contiene collegamenti. Comunque, i template dovrebbero contenere il nome dalla pagina corretto a cui puntano, e non rimandare su un redirect, in questo caso il link non funzionerà.

[modifica] Parametri

E' inoltre possibile includere un messaggio come template applicando dei parametri allo stesso template.

I parametri dei template possono essere numerici oppure nomi. La sintassi per aggiungere un messaggio con parametri è:

{{cosa|parametro=valore}}

con il tag {{{parametro}}} nel template, o

{{cosa|valore1|valore2}}

con i relativi tag {{{1}}}, {{{2}}}, ecc. nel template. (Nota che i tag-parametri nel template devono avere tre parentesi graffe e non due).

I parametri superflui sono ignorati, mentre nel caso di un numero di parametri inferiore al previsto, appariranno come link a template inesistenti.

Un esempio di template che accetta parametri è {{imagelicensing}}, che contiene riferimenti a "proprietario" e "fonte", come parametri, quindi componendo il template in questo modo:

{{imagelicensing|licenza=copyright|proprietario=[[Kivas Fajo]]|fonte=Kivas Fajo's ship}}

produrrà il seguente effetto:

Questo esempio mostra che è possibile utilizzare nei parametri anche un wiki-link. Non è invece necessario per i link esterni, in quanto, se corretti, saranno presentati automaticamente.

[modifica] Sostituzioni

Se si include la stringa "subst:" dopo la doppia parentesi graffa, MediaWiki sostituirà il testo del template nel wikitext, anzichè includerlo. L'effetto finale è che il testo corrente del template sarà salvato permanentemente, e non sarà aggiornato se e quando il template verrà aggiornato. Esempio:

{{subst:copyvio1}}

Quando "subst" viene applicato ad un template, una variabile di quel template viene copiata come tale nel wikitext.

Non puoi sostituire lo stesso template più di cinque volte per modifica (comunque questo si applica solo ad una singola modifica, eventualmente puoi farne una seconda ed aggiungerne altre cinque. Il perchè di tutte queste sostituzioni, non è comunque chiarito.)

[modifica] Uso

I Template sono utili per qualsiasi testo per il quale si renda necessario duplicare in due o più pagine, e non sia necessario per ciascuna copia modificarla indipendentemente, per adattarla alla pagina in cui si trova. Siccome è possibile utilizzare dei parametri, le versioni risultanti possono anche essere differenti, ed i valori dei parametri possono essere modificati ciascuno in maniera indipendente.

[modifica] Vedi anche

A template is a special type of page that has been designed so its content can be included in one or more other pages. Since a given template can be included in many pages, templates can help reduce duplication and promote a uniform style between pages.

Templates are usually located in the Template namespace, which means any page name beginning with Template:, such as Template:Name. However, any page can act as a template.

Contents

Referencing templates

Transcluded template

The content of a template can be added to a page by referencing it using the wiki markup: {{templatename}}. This references the template and includes its output at the point of insertion. Articles will be updated automatically when referenced templates are changed. A page that references templates cannot be edited to change the content of a referenced template, although a list of referenced templates will be displayed at the bottom of the page for convenience while editing it.

Substituting templates

Substituted template

A different way to use a template is to substitute its content into a page. This is done by inserting subst: immediately after the opening braces: {{subst:templatename}}. Once the page is saved, the link to the template is removed and the template output is substituted in its place and can be further edited. Any updates to the template will not affect the content that was substituted into the page.

Benefits of templates

Templates are used to add recurring messages to pages in a consistent way, to add boilerplate messages, to create infoboxes and navigational boxes, and to provide cross-language portability of texts.

Templates can also make it much easier for new and casual editors to use advanced designs, features and extensions by hiding confusing code.

Creating a template

In short, create the text you want to have copied onto the target pages on a page in the Template namespace. Creating Template:Templatename will allow users to insert {{templatename}} into a page to display your text.

See Help:Creating templates for details.

For an overview, see the quick guide to templates on Wikimedia's Meta-Wiki.

Creating an advanced template

To learn how to change the output of the template based on what the user inputs, see Help:Template parameters and Help:Parser functions.

Updating and adding standard templates

Wikia's Starter Pages and Templates wikis occasionally improve some of their documentation as well as adding new templates specifically designed for Wikia sites, and are therefore worth checking from time to time. For sites created before about December 2008, the Starter Pages wiki should be compared and ideally used for upgrading to its standard documentation system similar to that introduced in Wikipedia.