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]] | ||