Template:Mbox/doc: Difference between revisions
m →Usage: it's more than 3 params now |
ArrowHead294 (talk | contribs) m Note on dynamic stylesheet loading |
||
| Line 27: | Line 27: | ||
{{Mbox|text=Messagebox of '''protection''' type. Denotes pages that are protected from editing.|type=protection}} | {{Mbox|text=Messagebox of '''protection''' type. Denotes pages that are protected from editing.|type=protection}} | ||
=== Technical notes === | |||
This template uses MediaWiki's <code><nowiki>{{#tag: }}</nowiki></code> parser function to dynamically load the stylesheet based on parameters. | |||
Normally, TemplateStyles are loaded using a literal tag such as: | |||
<syntaxhighlight lang="wikitext"> | |||
<templatestyles src="mbox/styles.css" /> | |||
</syntaxhighlight> | |||
However, the <code>src</code> attribute of <code><nowiki><templatestyles></nowiki></code> does not accept template parameters when written directly (e.g. <code><nowiki><templatestyles src="{{{class}}}/styles.css" /></nowiki></code>), as it will produce an "Invalid title for TemplateStyles' <code>src</code> attribute" error. | |||
To work around this limitation, the <code>{{#tag:}}</code> parser function can be used instead: | |||
<syntaxhighlight lang="wikitext"> | |||
{{#tag: templatestyles||src={{{class|mbox}}}/styles.css}} | |||
</syntaxhighlight> | |||
This allows the stylesheet source to be constructed dynamically from template parameters. For example, when <code>class=alert</code> is passed, the template will load the stylesheet for <code>Template:Alert/styles.css</code> rather than the default Mbox styles. | |||
This approach is required whenever TemplateStyles must be selected conditionally or via parameters. | |||
=== See also === | === See also === | ||
* [[Template: Alert]] | * [[Template: Alert]] | ||
Revision as of 17:37, 3 February 2026
- This template is a metatemplate. It is used to build other templates and should not be used standalone, except for testing or simple usage.
| This template uses TemplateStyles: |
The Mbox template is a metatemplate which is used to create message boxes which are placed at the top of a page. It is intended to be used in other templates for messages which are expected to be used on multiple pages.
Usage
The template accepts the following parameters:
class: Defines the "class" of the message box ("mbox" for a standard message box, "alert" for alerts, etc.)type: Defines the color of the left border; the type should be chosen according to context, not for aesthetic reasons. Types are described in the next section.text: Message to be displayed in the box.icon: Icon to be displayed in the box, if provided. Icons appear on the left side of the message box.icon size: Size of the icon displayed. Default is 60px.
Types and examples
| Messagebox of delete type. Typically used for pages whose content is deprecated or to be deleted. |
| Messagebox of content type. Typically used for pages whose content requires verification or rewriting. |
| Messagebox of style type. Typically used for pages whose writing deviates from the wiki's standards. |
| Messagebox of ready type. Used to denote wiki features (such as templates) that are ready for use. |
| Messagebox of notice type. Used to denote general notices. Most messageboxes are of this type. |
| Messagebox of move type. Denotes pages that are to be moved. |
| Messagebox of protection type. Denotes pages that are protected from editing. |
Technical notes
This template uses MediaWiki's {{#tag: }} parser function to dynamically load the stylesheet based on parameters.
Normally, TemplateStyles are loaded using a literal tag such as:
<templatestyles src="mbox/styles.css" />
However, the src attribute of <templatestyles> does not accept template parameters when written directly (e.g. <templatestyles src="{{{class}}}/styles.css" />), as it will produce an "Invalid title for TemplateStyles' src attribute" error.
To work around this limitation, the </> parser function can be used instead:
{{#tag: templatestyles||src={{{class|mbox}}}/styles.css}}
This allows the stylesheet source to be constructed dynamically from template parameters. For example, when class=alert is passed, the template will load the stylesheet for Template:Alert/styles.css rather than the default Mbox styles.
This approach is required whenever TemplateStyles must be selected conditionally or via parameters.
