| Line 1: |
Line 1: |
| | Using templates can be easy or hard, depending on the template. But normally they are easy. | | Using templates can be easy or hard, depending on the template. But normally they are easy. |
| | | | |
| − | == '''Before you can attach your own template to any CP page, you will need to submit it for approval at [[Template Submission]].''' == | + | <div style="background-color:#dff; border:solid 1px blue; padding:5px; float:right; width:20em; margin-left:5px"><small><small><nowiki>{{mainpageright}}</nowiki></small></small></div> |
| | + | __TOC__ |
| | | | |
| | == Basic instructions == | | == Basic instructions == |
| − | <div style="background-color:#dff; border:solid 1px blue; padding:5px; float:right; width:20em"><small><small>{{mainpageright}}</small></small></div>
| |
| | | | |
| | A template is simply a page (usually a very brief one) that is inserted into another page. | | A template is simply a page (usually a very brief one) that is inserted into another page. |
| Line 19: |
Line 19: |
| | | | |
| | For example, the ''Welcome'' template that someone might have put on your user talk page has two parameters. One is the name of the user, and the other is the name of the person placing the welcome message. See the example below welcoming The Joker, placed by Batman: | | For example, the ''Welcome'' template that someone might have put on your user talk page has two parameters. One is the name of the user, and the other is the name of the person placing the welcome message. See the example below welcoming The Joker, placed by Batman: |
| − | <div style="width:65%"><small><small>{{welcome|Joker|sig=from Batman}}</small></small></div> | + | <nowiki><div style="width:65%"><small><small>{{welcome|Joker|sig=from Batman}}</small></small></div></nowiki> |
| | | | |
| − | (This was included on this page by typing <tt><small><nowiki>{{welcome|Joker|sig=from Batman}}</nowiki></small></tt>.<ref name="shrunk" />) | + | (This was included on this page by typing {{tt|<nowiki>{{welcome|Joker|sig=from Batman}}</nowiki>}}.<ref name="shrunk" />) |
| | | | |
| | "Pipe" characters (|) separate each parameter. | | "Pipe" characters (|) separate each parameter. |
| | | | |
| | Parameters can be optional or required, and they can be named or not named. In the example above, the first parameter ("Joker") was not named, but the second ("from Batman") was named ''sig''. Two points need to be kept in mind with parameters: | | Parameters can be optional or required, and they can be named or not named. In the example above, the first parameter ("Joker") was not named, but the second ("from Batman") was named ''sig''. Two points need to be kept in mind with parameters: |
| − | * Named parameters can be supplied in any order. | + | * '''Named parameters''' can be supplied in any order. |
| − | * Un-named parameters must be supplied in the correct order. | + | * '''Un-named parameters''' must be supplied in the correct order. |
| | + | See below for how parameters are provided to templates. |
| | + | |
| | Each template has (or will have) a list of parameters, looking something like this (this one is from the {{tl|welcome}} template): | | Each template has (or will have) a list of parameters, looking something like this (this one is from the {{tl|welcome}} template): |
| | {{Parms| | | {{Parms| |
| Line 40: |
Line 42: |
| | You can assume that if no default is shown for a parameter that is not required, the result will be blank (i.e. in this case, the welcome message would not show who it was from). | | You can assume that if no default is shown for a parameter that is not required, the result will be blank (i.e. in this case, the welcome message would not show who it was from). |
| | | | |
| − | You will notice that named parameters have the parameter name followed by an equals sign (=) followed by whatever you want that to be.
| + | To supply a value to a '''named parameter''', put the parameter name followed by an equals sign (=) followed by whatever you want that to be. In the example above, this is {{tt|<nowiki>sig=~~~~</nowiki>}}. |
| | + | |
| | + | Parameters shown with numbers are the '''un-named parameters'''. You ''can'' treat them as named parameters, by typing {{tt|1=1=''your text''}}, but this is not necessary, except in the case that you want your text to include an equals sign (=). Normally you just supply the value, such as {{tt|YourUserName}}. |
| | + | |
| | + | Each parameter is separated from each other, and from the template name, by a 'pipe' character: {{tt|{{!}}}}. |
| | | | |
| − | Parameters shown with numbers are the un-named parameters. You ''can'' treat them as named parameters, by typing 1=''your text'', but this is not necessary, except in the case that you want your text to include an equals sign (=).
| + | So supplying both parameters in the {{tl|welcome}} template would look like this: {{tt|<nowiki>{{welcome|YourUserName|sig=~~~~}}</nowiki>}}. |
| | | | |
| | === What do you pass to parameters? === | | === What do you pass to parameters? === |
| Line 50: |
Line 56: |
| | In some cases, however, specific text must be supplied. The {{tl|Bible ref}} template, for example, expects a book of the Bible for the "book" parameter, and giving it something that is not a book of the Bible will break the link to BibleGateway that the template creates. | | In some cases, however, specific text must be supplied. The {{tl|Bible ref}} template, for example, expects a book of the Bible for the "book" parameter, and giving it something that is not a book of the Bible will break the link to BibleGateway that the template creates. |
| | | | |
| − | In many cases you can supply a blank value to the parameter. You can set a parameter to be blank by typing nothing after the pipe character for an unnamed parameter, or nothing after the equals sign for a named parameter. For example, if you wanted the welcome template to not show "Joker" or "from Batman", you could type <tt><small><nowiki>{{welcome||sig=}}</nowiki></small></tt> | + | In many cases you can supply a blank value to the parameter. You can set a parameter to be blank by typing nothing after the pipe character for an unnamed parameter, or nothing after the equals sign for a named parameter. For example, if you wanted the welcome template to not show "Joker" or "from Batman", you could type {{tt|<nowiki>{{welcome||sig=}}</nowiki>}}. |
| | | | |
| | However, a well-written template will allow you to simply omit the parameter altogether, as the {{tl|welcome}} template does with the ''sig'' parameter. | | However, a well-written template will allow you to simply omit the parameter altogether, as the {{tl|welcome}} template does with the ''sig'' parameter. |
| | + | |
| | + | == Notes == |
| | + | {{reflist}} |