(Starting) |
No edit summary |
||
Line 3: | Line 3: | ||
Templates allow you to pass '''parameters''' that can be used to affect the content or design of the template. |
Templates allow you to pass '''parameters''' that can be used to affect the content or design of the template. |
||
+ | == Simple replacement == |
||
− | For example: |
||
+ | Using the example of a simple box, the following when placed on a template page called <code>Template:Box</code>: |
||
+ | |||
+ | <pre> |
||
+ | <div style="width:10em; height:5em; border:1px solid #333; background-color:#666; color:#fff; text-align:center; padding-top:2em;">{{{1}}}</div> |
||
+ | </pre> |
||
+ | |||
+ | Produces the following box on the template page: |
||
+ | |||
+ | <div style="width:10em; height:5em; border:1px solid #333; background-color:#666; color:#fff; text-align:center; padding-top:2.5em;">{{{1}}}</div> |
||
+ | |||
+ | Next, on an article, you could type: |
||
<code><nowiki>{{box|text}}</nowiki></code> |
<code><nowiki>{{box|text}}</nowiki></code> |
||
+ | This would produce: |
||
− | ...might produce a box containing <code>text</code>. |
||
+ | |||
+ | <div style="width:10em; height:5em; border:1px solid #333; background-color:#666; color:#fff; text-align:center; padding-top:2.5em;">text</div> |
||
+ | |||
+ | This is because <code><nowiki>{{{1}}}</nowiki></code> tells the wiki to pass the first parameter of the template here. This can be extended with <code><nowiki>{{{2}}}</nowiki></code>, <code><nowiki>{{{3}}}</nowiki></code>, ad infinitum. The number represents the number of the parameter: |
||
+ | |||
+ | <code><nowiki>{{box|first parameter|second parameter|third parameter}}</nowiki></code> |
||
+ | |||
+ | If you wish not to use a certain parameter, you can leave it blank, but the | must still be included. For example: |
||
+ | |||
+ | <code><nowiki>{{box|first parameter||third parameter}}</nowiki></code> |
||
+ | |||
+ | == Named parameters == |
||
Alternatively: |
Alternatively: |
Revision as of 11:05, 14 May 2008
Templates allow you to pass parameters that can be used to affect the content or design of the template.
Simple replacement
Using the example of a simple box, the following when placed on a template page called Template:Box
:
<div style="width:10em; height:5em; border:1px solid #333; background-color:#666; color:#fff; text-align:center; padding-top:2em;">{{{1}}}</div>
Produces the following box on the template page:
Next, on an article, you could type:
{{box|text}}
This would produce:
This is because {{{1}}}
tells the wiki to pass the first parameter of the template here. This can be extended with {{{2}}}
, {{{3}}}
, ad infinitum. The number represents the number of the parameter:
{{box|first parameter|second parameter|third parameter}}
If you wish not to use a certain parameter, you can leave it blank, but the | must still be included. For example:
{{box|first parameter||third parameter}}
Named parameters
Alternatively:
{{box|bgcolor=yellow|textcolor=blue|caption=A yellow house}}
...might produce a box with a yellow background and blue text, with a caption describing it as such.