Module:IconData/doc
More actions
This is the documentation page for Module:IconData
Resolves a lookup key against a named dataset and delegates rendering to Module:Icon. It is the data layer of the icon system, sitting between dataset-specific wrapper templates and the icon renderer.
Editors placing dataset-driven icons on a page should use a wrapper template such as Template:Ammo or Template:Condition rather than invoking this module directly.
Datasets
Datasets are stored as data modules at Module:IconData/<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. When an entry is found, its fields and any arguments supplied by the calling template are forwarded to Icon.buildIcon; each entry contains:
icon(required): file name of the icon.invert(optional): whether to invert the icon in light mode.
Example dataset structure using Module:IconData/Currency:
return {
coin = { icon = "Icon_Coin.png",
invert = true },
cred = { icon = "Icon_Cred.png" },
token = { icon = "Icon_Raider_Token.png" },
merit = { icon = "Icon_Merit.png" },
seed = { icon = "Icon_Nature.png",
invert = true },
skill = { icon = "Icon_Skill_Point.png",
invert = true },
}
Wrappers
Wrapper templates are the editor-facing interface of the icon system. Each wrapper template invokes Module:IconData 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:IconData|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:IconData/<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:IconData|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 main, rendered as an inline {{{1}}}, and tracked via Category:Pages with icon errors.
See also
- Module:Icon: performs the actual rendering.