Module:Icon/data
More actions
This page documents the data layer of the icon system. Datasets store icon metadata, including file names and CSS classes, used by Module:Icon when resolving icons by key or filename. Editors placing dataset-driven icons on a page should use a wrapper template such as Template:Ammo or Template:Currency rather than passing dataset arguments directly.
Datasets
Datasets are stored as data modules at Module:Icon/data/<DatasetName> and cached via mw.loadData. A key is a string passed to the wrapper template that identifies which entry to look up in the dataset; it is lowercased before matching. When an entry is found, its fields and any arguments supplied by the calling template are forwarded to Module:Icon; each entry contains:
icon(required): file name of the icon.classes(optional): list of CSS classes to apply to the icon wrapper span.
Example dataset structure using Module:Icon/data/currency:
return {
coin = { icon = "Icon_Coin.png",
classes = {"invert-on-light"} },
cred = { icon = "Icon_Cred.png" },
token = { icon = "Icon_Raider_Token.png" },
merit = { icon = "Icon_Merit.png" },
seed = { icon = "Icon_Nature.png",
classes = {"invert-on-light"} },
skill = { icon = "Icon_Skill_Point.png",
classes = {"invert-on-light"} },
}
Wrappers
Wrapper templates are the editor-facing interface of the icon system. Each wrapper template invokes Module:Icon with a fixed dataset name and forwards arguments from the caller to the module, keeping the dataset and module invisible at the call site.
Example wrapper template using Template:Currency:
<includeonly>{{#invoke:Icon|main
| dataset = Currency
| key = {{{key|{{{1|}}}}}}
| text = {{formatnum:{{{text|{{{2|}}}}}}}}
| link = {{{link|{{{3|}}}}}}
| size = {{{size|}}}}}<!--
--></includeonly><noinclude><!--
-->{{Documentation}}</noinclude>
Adding a new dataset and wrapper
Replace <DatasetName> with the name of the new dataset throughout.
- Create
Module:Icon/data/<DatasetName>using the dataset structure below. - Create a wrapper template at
Template:<DatasetName>using the wrapper structure below.
return {
key = { icon = "Icon_Name.png" },
}
<includeonly>{{#invoke:Icon|main
| dataset = <DatasetName>
| key = {{{key|{{{1|}}}}}}
| text = {{{text|{{{2|}}}}}}
| link = {{{link|{{{3|}}}}}}
| size = {{{size|}}}}}<!--
--></includeonly><noinclude><!--
-->{{Documentation}}</noinclude>
The key argument is lowercased before lookup, so callers may pass keys in any case. The text, link, and size arguments are forwarded to and documented at Module:Icon.
Errors
Raises an error when:
- No
datasetis supplied. - No
keyis supplied for the given dataset. - The supplied
keyis not present in the dataset. - The named dataset does not exist;
mw.loadDataraises a "module not found" error.
All errors are caught by Icon.main, rendered as an inline <span class="error">, and tracked via Category:Pages with icon errors.
See also
- Module:Icon: the icon engine; handles rendering and index resolution.
- Module:Icon/index: maps icon filenames to dataset locations.