Difference between revisions of "Manual:Template/Example/Notification Box"
[quality revision] | [quality revision] |
(Created page with "==Template example: Notification box== To emphasize text passages, it is common to use a type of notifcation box. In this example, we create a notification box that can be u...") (Tag: Visual edit) |
(Tag: 2017 source edit) |
Contents
Template example: Notification box[edit | edit source]
To emphasize text passages, it is common to use a type of notifcation box.
In this example, we create a notification box that can be used to show a warning, a tip or a note:
Warning: Don't leave the machine unattended while it is running.
Tip: It is best to use the built-in numbering functionality to avoid output errors.
Note: We will switch to a new accounting system soon. The current system will be offline starting January, 1st.
The color of the box and the box label change automatically depending on the type of box a user selects.
Creating the template[edit | edit source]
- Create the page Template:Box Note
-
Add the template content and save the page:
<div class="infobox {{{boxtype}}}"> <span class="boxlabel"> {{#switch: {{{boxtype}}} | note = Note: | tip = Tip: | warning = Warning: | #default = Note: }} </span> {{{Note text}}} </div>
What this code does:
-
The container (
<div>...</div>
) is used for styling the box. It has the style classes infobox and{{{boxtype}}}
. The boxtype parameter provides the actual value the user chooses when using the template. -
The
<span>...</span>
contains the label for the box. It displays the label for the box type the user chooses. It has the style class boxlabel which is used to format the label. -
{{{Note text}}}
is the placeholder for the actual text the user creates on a particular page.
...
tag to ensure that this part of the template is not transcluded in the target page that uses the actual template. This template sections function is to describe the parameters of the template. It also populates the form for visual editing:
<noinclude>
<templatedata>
{
"params": {
"boxtype": {
"description": "Possible values: note, tip, warning",
"example": "note",
"type": "string",
"default": "note",
"required": true
},
"Note text": {}
},
"description": "To add standard infoboxes such as notes or related links to a page"
}
</templatedata>
</noinclude>
- It lists the two parameters (boxtype and Note text), separated by a comma.
- It lists the parameter objects (optional): description, example, type, etc. For a full ist of template data objects, see www.mediawiki.org/wiki/Extension:TemplateData#Param_object
- It describes the purpose of the template (description) so that users can distinguish it from similar templates.
Creating the template styles[edit | edit source]
dgdfg
Using the template[edit | edit source]
dfgdfg
==Template example: Notification box== To emphasize text passages, it is common to use a type of notifcation box. In this example, we create a notification box that can be used to show a warning, a tip or a note: {{Box Note|boxtype=warning|Note text=Don't leave the machine unattended while it is running.}} {{Box Note|boxtype=tip|Note text=It is best to use the built-in numbering functionality to avoid output errors.}} {{Box Note|boxtype=note|Note text=We will switch to a new accounting system soon. The current system will be offline starting January, 1st.}} [[File:boxnote-outputs.png|480x480px]] The color of the box and the box label change automatically depending on the type of box a user selects. == Creating the template == # '''Create''' the page ''Template:Box Note'' # '''Add the template content''' and save the page:<syntaxhighlight lang="html"> <div class="infobox {{{boxtype}}}"> <span class="boxlabel"> {{#switch: {{{boxtype}}} | note = Note: | tip = Tip: | warning = Warning: | #default = Note: }} </span> {{{Note text}}} </div> </syntaxhighlight><br /> What this code does: * The container (<code><nowiki><div>...</div></nowiki></code>) is used for styling the box. It has the style classes ''infobox'' and <code>''<nowiki>{{{boxtype}}}</nowiki>''</code>. The boxtype parameter provides the actual value the user chooses when using the template. * The <code><nowiki><span>...</span></nowiki></code> contains the label for the box. It displays the label for the box type the user chooses. It has the style class ''boxlabel'' which is used to format the label. * <code><nowiki>{{{Note text}}}</nowiki></code> is the placeholder for the actual text the user creates on a particular page. To make it easy for users to insert and use this template in visual editing mode, we include a <nowiki><templatedata> section in the template. It uis wrapped in a </nowiki><code><noinclude>...</noinclude></code> tag to ensure that this part of the template is not transcluded in the target page that uses the actual template. This template sections function is to describe the parameters of the template. It also populates the form for visual editing:<syntaxhighlight lang="html"> <noinclude> <templatedata> { "params": { "boxtype": { "description": "Possible values: note, tip, warning", "example": "note", "type": "string", "default": "note", "required": true }, "Note text": {} }, "description": "To add standard infoboxes such as notes or related links to a page" } </templatedata> </noinclude> </syntaxhighlight>What this code does: * It lists the two parameters (''boxtype'' and ''Note text''), separated by a comma. * It lists the parameter objects (optional): description, example, type, etc. For a full ist of template data objects, see [[mediawikiwiki:Extension:TemplateData#Param_object|www.mediawiki.org/wiki/Extension:TemplateData#Param_object]] * It describes the purpose of the template (''description'') so that users can distinguish it from similar templates. == Creating the template styles == dgdfg == Using the template == dfgdfg
Line 3: | Line 3: | ||
In this example, we create a notification box that can be used to show a warning, a tip or a note: | In this example, we create a notification box that can be used to show a warning, a tip or a note: | ||
− | {{ | + | |
− | {{ | + | [[File:boxnote-outputs.png|480x480px]] |
− | {{ | + | |
+ | The color of the box and the box label change automatically depending on the type of box a user selects. | ||
+ | |||
+ | == Creating the template == | ||
+ | |||
+ | # '''Create''' the page ''Template:Box Note'' | ||
+ | # '''Add the template content''' and save the page:<syntaxhighlight lang="html"> | ||
+ | <div class="infobox {{{boxtype}}}"> | ||
+ | <span class="boxlabel"> | ||
+ | {{#switch: {{{boxtype}}} | ||
+ | | note = Note: | ||
+ | | tip = Tip: | ||
+ | | warning = Warning: | ||
+ | | #default = Note: | ||
+ | }} | ||
+ | </span> | ||
+ | {{{Note text}}} | ||
+ | </div> | ||
+ | </syntaxhighlight><br /> | ||
+ | |||
+ | What this code does: | ||
+ | |||
+ | * The container (<code><nowiki><div>...</div></nowiki></code>) is used for styling the box. It has the style classes ''infobox'' and <code>''<nowiki>{{{boxtype}}}</nowiki>''</code>. The boxtype parameter provides the actual value the user chooses when using the template. | ||
+ | * The <code><nowiki><span>...</span></nowiki></code> contains the label for the box. It displays the label for the box type the user chooses. It has the style class ''boxlabel'' which is used to format the label. | ||
+ | * <code><nowiki>{{{Note text}}}</nowiki></code> is the placeholder for the actual text the user creates on a particular page. | ||
+ | |||
+ | To make it easy for users to insert and use this template in visual editing mode, we include a <nowiki><templatedata> section in the template. It uis wrapped in a </nowiki><code><noinclude>...</noinclude></code> tag to ensure that this part of the template is not transcluded in the target page that uses the actual template. This template sections function is to describe the parameters of the template. It also populates the form for visual editing:<syntaxhighlight lang="html"> | ||
+ | <noinclude> | ||
+ | <templatedata> | ||
+ | { | ||
+ | "params": { | ||
+ | "boxtype": { | ||
+ | "description": "Possible values: note, tip, warning", | ||
+ | "example": "note", | ||
+ | "type": "string", | ||
+ | "default": "note", | ||
+ | "required": true | ||
+ | }, | ||
+ | "Note text": {} | ||
+ | }, | ||
+ | "description": "To add standard infoboxes such as notes or related links to a page" | ||
+ | } | ||
+ | </templatedata> | ||
+ | </noinclude> | ||
+ | </syntaxhighlight>What this code does: | ||
+ | |||
+ | * It lists the two parameters (''boxtype'' and ''Note text''), separated by a comma. | ||
+ | * It lists the parameter objects (optional): description, example, type, etc. For a full ist of template data objects, see [[mediawikiwiki:Extension:TemplateData#Param_object|www.mediawiki.org/wiki/Extension:TemplateData#Param_object]] | ||
+ | * It describes the purpose of the template (''description'') so that users can distinguish it from similar templates. | ||
+ | |||
+ | == Creating the template styles == | ||
+ | dgdfg | ||
+ | |||
+ | |||
+ | |||
+ | == Using the template == | ||
+ | |||
+ | dfgdfg |