User:Adaz: Difference between revisions

Jump to navigation Jump to search
22 bytes added ,  12 November 2022
m
no edit summary
mNo edit summary
mNo edit summary
Line 72: Line 72:


Dans la documentation du modèle, il y a aussi une liste des paramètres et comment ils sont censés être utilisés. Il y a souvent des exemples pour illustrer les différentes façons dont les paramètres peuvent être utilisés.
Dans la documentation du modèle, il y a aussi une liste des paramètres et comment ils sont censés être utilisés. Il y a souvent des exemples pour illustrer les différentes façons dont les paramètres peuvent être utilisés.
{{BeingTranslated}}
== La création de nouveaux modèles ==
=== Choosing a good name ===
Consider giving the template a meaningful name.  Usually one would try to only have the initial character upper case.  If you are mimicking a template on another wiki, using its name might be a good idea.  If the template will be used very often it might actually be a good idea to use a very short name or an abbreviation, but proper categorisation and documentation will then be even more important.  Do note that parameter names are case sensitive except for the first character.


=== Search first ===
===Choisir un nom explicite===
To create a new template, please start by using the search function. This way you will find if there already is a template with that name or if there is one with a very similar name. If there is no template with that name you will be presented with the option to create that page. Click on the red link to open up a edit window.
Envisagez de donner au modèle un nom significatif. Habituellement, le caractère initial est en majuscule. Si vous céez un modèle à partir d'un autre wiki, utiliser son nom peut être une bonne idée. Si le modèle est utilisé très souvent, il peut être judicieux d'utiliser un nom très court ou une abréviation, mais une catégorisation et une documentation appropriées seront alors encore plus importantes. Notez que les noms de paramètres sont sensibles à la casse, sauf pour le premier caractère.


=== Things to include ===
===Commencez par rechercher===
Pour créer un nouveau modèle, veuillez commencer par utiliser la fonction de recherche. De cette façon, vous saurez s'il existe déjà un modèle portant ce nom ou s'il en existe un avec un nom très similaire. S'il n'y a pas de modèle avec ce nom, vous aurez la possibilité de créer cette page. Cliquez sur le lien rouge pour ouvrir une fenêtre d'édition.
 
===Things to include===
Two important things to add to your template is template documentation, preferably using {{tl|informative template}} and if possible to put the template in a more fitting category than [[:Category:Templates]].
Two important things to add to your template is template documentation, preferably using {{tl|informative template}} and if possible to put the template in a more fitting category than [[:Category:Templates]].


Unless it is a very simple template it can be a good thing to start by writing the documentation as this might help you figuring out the last few things in what you want the template to do and how you want it to do that, and then more or less use the documentation as reference when typing the template itself.
Unless it is a very simple template it can be a good thing to start by writing the documentation as this might help you figuring out the last few things in what you want the template to do and how you want it to do that, and then more or less use the documentation as reference when typing the template itself.


=== Preview often ===
===Preview often===
Do remember that you can, and should use the preview button now and then, or at least one before saving, in order to catch any errors before saving.  One way of debugging a template is to add obvious clues as to where in a template something got wrong, for example 1?, 2?...  This can be really helpful in some cases,  though in other cases it will be obvious.  Some common mistakes are the same ones as on article pages:  Missing end markers in tables and missing end tags or end tags with missing slashes.
Do remember that you can, and should use the preview button now and then, or at least one before saving, in order to catch any errors before saving.  One way of debugging a template is to add obvious clues as to where in a template something got wrong, for example 1?, 2?...  This can be really helpful in some cases,  though in other cases it will be obvious.  Some common mistakes are the same ones as on article pages:  Missing end markers in tables and missing end tags or end tags with missing slashes.


While the template always can be fixed if there are errors it is better to have an extra preview than an extra edit.  Do note that the template will be lost if you do not save it.
While the template always can be fixed if there are errors it is better to have an extra preview than an extra edit.  Do note that the template will be lost if you do not save it.


== Modification d'un modèle ==
== Modification d'un modèle==
Editing a template is often as easy as editing a normal wiki page.  Lets say you want to edit a template with the name ''what you always wanted to know''. Either search for the template using the template namespace like ''Template:What you always wanted to know'' or click on a link to get you there.
Editing a template is often as easy as editing a normal wiki page.  Lets say you want to edit a template with the name ''what you always wanted to know''. Either search for the template using the template namespace like ''Template:What you always wanted to know'' or click on a link to get you there.


Line 97: Line 96:
Always try to add documentation to templates missing that, preferably using {{tl|informative template}}.
Always try to add documentation to templates missing that, preferably using {{tl|informative template}}.


=== Passing unnamed parameters ===
===Passing unnamed parameters===
Passing parameters to templates make them a lot more useful.  Unnamed parameters can be used in the order they are passed, in essence <tt><nowiki>{{{1}}}</nowiki></tt>, <tt><nowiki>{{{2}}}</nowiki></tt> etc.  Consider the following template, ''Template:Hello'':
Passing parameters to templates make them a lot more useful.  Unnamed parameters can be used in the order they are passed, in essence <tt><nowiki>{{{1}}}</nowiki></tt>, <tt><nowiki>{{{2}}}</nowiki></tt> etc.  Consider the following template, ''Template:Hello'':
<pre>Hello, {{{1|}}}{{{2|stranger}}}!</pre>
<pre>Hello, {{{1|}}}{{{2|stranger}}}!</pre>
Line 108: Line 107:
Hello, Dr. Falken!
Hello, Dr. Falken!


=== Default values ===
===Default values===
You might wonder what that vertical stroke and the text following, <tt><nowiki>{{{</nowiki>1'''|'''<nowiki>}}}{{{</nowiki>2'''|stranger'''<nowiki>}}}</nowiki></tt>, in ''Template:Hello'' does.  Most of you will already have guessed that they are default values.  Having at least an ''empty'' default value is a good practice, as templates otherwise will break when passed an empty parameter.  Here is what happens when the above template is used without parameters:
You might wonder what that vertical stroke and the text following, <tt><nowiki>{{{</nowiki>1'''|'''<nowiki>}}}{{{</nowiki>2'''|stranger'''<nowiki>}}}</nowiki></tt>, in ''Template:Hello'' does.  Most of you will already have guessed that they are default values.  Having at least an ''empty'' default value is a good practice, as templates otherwise will break when passed an empty parameter.  Here is what happens when the above template is used without parameters:
  <pre>{{hello}}</pre>
  <pre>{{hello}}</pre>
Line 117: Line 116:
<nowiki>Hello, {{{1}}}{{{2}}}!</nowiki>
<nowiki>Hello, {{{1}}}{{{2}}}!</nowiki>


=== Passing named parameters ===
===Passing named parameters===
While using a template with named parameters can be a bit more of typing, they are not that much extra typing when editing a template.  They are however practical some other ways, they can be passed to a template in any order and, more important, they are named (as in not numbered).  That last thing makes them immensely more useful in complex templates.
While using a template with named parameters can be a bit more of typing, they are not that much extra typing when editing a template.  They are however practical some other ways, they can be passed to a template in any order and, more important, they are named (as in not numbered).  That last thing makes them immensely more useful in complex templates.


Line 130: Line 129:
Hello, Dr. Falken!
Hello, Dr. Falken!


=== To include or not include ===
===To include or not include===
Sometimes you have content in a template that you do not want to be transcluded or that you want to have transcluded but not included in the template.  Consider for example the template documentation, of course you would not want it to be on every page the template is used on, also, sometimes you want a template to add a category to the page it is used on, but not to the template itself. This can be done using the <tt><nowiki><noinclude></nowiki></tt> and <tt><nowiki><includeonly></nowiki></tt> tags.
Sometimes you have content in a template that you do not want to be transcluded or that you want to have transcluded but not included in the template.  Consider for example the template documentation, of course you would not want it to be on every page the template is used on, also, sometimes you want a template to add a category to the page it is used on, but not to the template itself. This can be done using the <tt><nowiki><noinclude></nowiki></tt> and <tt><nowiki><includeonly></nowiki></tt> tags.


Line 138: Line 137:


  <nowiki>Hello, {{{1|}}}{{{2|stranger}}}!<includeonly>[[Category:Pages that says hello]]</includeonly><noinclude>
  <nowiki>Hello, {{{1|}}}{{{2|stranger}}}!<includeonly>[[Category:Pages that says hello]]</includeonly><noinclude>
{{Informative template|1=
{{Informative template|1=
__NOTOC__
__NOTOC__
== Goal ==
== Goal ==
This template can be used to show a friendly hello.
This template can be used to show a friendly hello.
 
Adding this template to a page will automatically add that page to [[:Category:Pages that says hello]].
Adding this template to a page will automatically add that page to [[:Category:Pages that says hello]].
 
== Usage ==
== Usage ==
&lt;nowiki&gt;{{&lt;/nowiki&gt;'''hello'''&lt;nowiki&gt;|&lt;/nowiki&gt;''title''&lt;nowiki&gt;|&lt;/nowiki&gt;''name''&lt;nowiki&gt;}}&lt;/nowiki&gt;
  &lt;nowiki&gt;{{&lt;/nowiki&gt;'''hello'''&lt;nowiki&gt;|&lt;/nowiki&gt;''title''&lt;nowiki&gt;|&lt;/nowiki&gt;''name''&lt;nowiki&gt;}}&lt;/nowiki&gt;
 
;parameter:  Optional title, for example "<tt>Dr.</tt>"
;parameter:  Optional title, for example "<tt>Dr.</tt>"
 
;parameter:  Optional name, defaults to "<tt>stranger</tt>"
;parameter:  Optional name, defaults to "<tt>stranger</tt>"
 
== Examples ==
== Examples ==
<pre>{{hello|Dr.|Falken}}</pre>
  <pre>{{hello|Dr.|Falken}}</pre>
Hello, Dr. Falken!
Hello, Dr. Falken!
 
<pre>{{hello}}</pre>
  <pre>{{hello}}</pre>
Hello, stranger!
Hello, stranger!
}}
[[Category:Hello templates]]
</noinclude></nowiki>


}}
===Category suppression===
 
[[Category:Hello templates]]
</noinclude></nowiki>
 
=== Category suppression ===
Sometimes it is helpful if a template suppresses categorisation and only categorizes some of the pages it is put on.  There is a few templates that can be used for that in [[:Category:Namespace templates]].  Most of them uses the namespace of the page the template is put on. For example '''''Help talk:'''Templates'' is in the ''Help talk'' namespace.
Sometimes it is helpful if a template suppresses categorisation and only categorizes some of the pages it is put on.  There is a few templates that can be used for that in [[:Category:Namespace templates]].  Most of them uses the namespace of the page the template is put on. For example '''''Help talk:'''Templates'' is in the ''Help talk'' namespace.


Line 175: Line 174:


  <nowiki>
  <nowiki>
...
...
}}
}}
 
{{main other|[[Category:Hello templates]]}}
{{main other|[[Category:Hello templates]]}}
</noinclude></nowiki>
</noinclude></nowiki>


Apart from '''demospace''' some templates will have a '''nocat''' parameter that when not empty or set as '''nocat = yes''' will suppress categorisation altogether.
Apart from '''demospace''' some templates will have a '''nocat''' parameter that when not empty or set as '''nocat = yes''' will suppress categorisation altogether.


== Traduire un modèle ==
==Traduire un modèle==
Templates are translated in a different way than [[Help:Translate|normal articles]].  Instead of creating another page for each translation, all translations are written within one template.  To do that one can use the {{tl|LangSwitch}} template, for example like below.
Templates are translated in a different way than [[Help:Translate|normal articles]].  Instead of creating another page for each translation, all translations are written within one template.  To do that one can use the {{tl|LangSwitch}} template, for example like below.


  <nowiki>[http://{{LangSwitch
  <nowiki>[http://{{LangSwitch
| en =  <!-- English -->
| en =  <!-- English -->
en
en
| de =  <!-- German -->
| de =  <!-- German -->
de
de
| fr =  <!-- French -->
| fr =  <!-- French -->
fr
fr
}}.wikipedia.org Wikipedia]</nowiki>
}}.wikipedia.org Wikipedia]</nowiki>


  <nowiki>{{LangSwitch
  <nowiki>{{LangSwitch
| en =  <!-- English -->
| en =  <!-- English -->
{{ The template with English contents }}
{{ The template with English contents }}
| de =  <!-- German -->
| de =  <!-- German -->
{{ The template with German contents }}
{{ The template with German contents }}
| fr =  <!-- French -->
| fr =  <!-- French -->
{{ The template with French contents }}
{{ The template with French contents }}
}}</nowiki>
}}</nowiki>


{{note|Many templates use tables and have to start from the beginning of the line, like in the above example.}}
{{note|Many templates use tables and have to start from the beginning of the line, like in the above example.}}
Line 212: Line 211:


  <nowiki>{{LangSwitch
  <nowiki>{{LangSwitch
...
...
| lang = fr }}</nowiki>
| lang = fr }}</nowiki>


== Edition avancée d'un modèle ==
==Edition avancée d'un modèle==
The templates can contain some very advanced and often complex code, but even easier code can do great things to make life easier for you as an editor using it later.
The templates can contain some very advanced and often complex code, but even easier code can do great things to make life easier for you as an editor using it later.


While this page will not go into details, there is a few secrets to more advanced templates:
While this page will not go into details, there is a few secrets to more advanced templates:
;Tables: Wiki tables are tricky to understand, but can do a lot for any kind of box template and small layouts.
;Tables:Wiki tables are tricky to understand, but can do a lot for any kind of box template and small layouts.


;Magic words: Magic words are mostly all uppercase and many of them at first look like templates.  Some of them are for example <tt><nowiki>{{CURRENTMONTHNAME}}</nowiki></tt> and <tt><nowiki>__NOTOC__</nowiki></tt>.
;Magic words:Magic words are mostly all uppercase and many of them at first look like templates.  Some of them are for example <tt><nowiki>{{CURRENTMONTHNAME}}</nowiki></tt> and <tt><nowiki>__NOTOC__</nowiki></tt>.


;Parser functions: Parser functions allow more or less regular programming with conditionals, switches, string formatting etc.  One of them is <tt>#if</tt>, <tt><nowiki>{{</nowiki>'''#if:''' ''string'' | ''passed if non-empty'' | ''passed if empty'' <nowiki>}}</nowiki></tt>.
;Parser functions:Parser functions allow more or less regular programming with conditionals, switches, string formatting etc.  One of them is <tt>#if</tt>, <tt><nowiki>{{</nowiki>'''#if:''' ''string'' | ''passed if non-empty'' | ''passed if empty'' <nowiki>}}</nowiki></tt>.


;HTML: It might seem a bit funny to mention it, but sometimes you forget that you can use (some) html tags in a MediaWiki wiki.
;HTML:It might seem a bit funny to mention it, but sometimes you forget that you can use (some) html tags in a MediaWiki wiki.


;Cascading style sheets: Like magic words and parser functions can do magic for the functionality of a template CSS can do magic for its appearance.
; Cascading style sheets:Like magic words and parser functions can do magic for the functionality of a template CSS can do magic for its appearance.


A good hint on getting more readable template source is that well placed HTML comments (<tt>&lt;!-- Comment --&gt;</tt>) will help a lot.   
A good hint on getting more readable template source is that well placed HTML comments (<tt>&lt;!-- Comment --&gt;</tt>) will help a lot.   


== Liens connexes ==
==Liens connexes==
* {{mediawiki|Help:Templates|MediaWiki template help}}
*
{{mediawiki|Help:Templates|MediaWiki template help}}


=== Advanced template help ===
===Advanced template help===
* [http://meta.wikimedia.org/wiki/Meta:About_Meta Mediawiki Meta]
*[http://meta.wikimedia.org/wiki/Meta:About_Meta Mediawiki Meta]
** [http://meta.wikimedia.org/wiki/Help:Template Meta:Help:Template]
**[http://meta.wikimedia.org/wiki/Help:Template Meta:Help:Template]
** [http://meta.wikimedia.org/wiki/Help:Advanced_templates Meta:Help:Advanced templates]
**[http://meta.wikimedia.org/wiki/Help:Advanced_templates Meta:Help:Advanced templates]
** [http://meta.wikimedia.org/wiki/Help:Table Meta:Help:Table]
**[http://meta.wikimedia.org/wiki/Help:Table Meta:Help:Table]
* {{mediawiki|Project:About}}
*{{mediawiki|Project:About}}
** {{mediawiki|Help:Tables}}
**{{mediawiki|Help:Tables}}
** {{mediawiki|Help:Magic words}}
**{{mediawiki|Help:Magic words}}
** {{mediawiki|Help:Extension:ParserFunctions}}
**{{mediawiki|Help:Extension:ParserFunctions}}
* [http://www.w3.org/TR/CSS2/ Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification]
*[http://www.w3.org/TR/CSS2/ Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification]


[[Category:Help]]
[[Category:Help]]
482

edits

Navigation menu