[unchecked revision] | [checked revision] |
m (Use new "Data file module" template.) |
No edit summary Tag: 2017 source edit |
||
(3 intermediate revisions by one other user not shown) | |||
Line 4: | Line 4: | ||
The data file is currently used in at least the following modules: | The data file is currently used in at least the following modules: | ||
* [[Module:Infobox_Animal]]: see [[Template:Infobox_Animal]] for more details. | * [[Module:Infobox_Animal]]: see [[Template:Infobox_Animal]] for more details. | ||
* [[Module: | * [[Module:TableAnimals]]: see [[Template:AnimalsTable]] for more details. | ||
* [[Module: | * [[Module:TableFish]]: see [[Template:FishTable]] for more details. | ||
== Usage == | == Usage == | ||
Line 24: | Line 24: | ||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Eco | <includeonly>[[Category:Eco data files]]</includeonly> |
Latest revision as of 16:01, 13 June 2024
Documentation[edit source]
The data file is currently used in at least the following modules:
- Module:Infobox_Animal: see Template:Infobox_Animal for more details.
- Module:TableAnimals: see Template:AnimalsTable for more details.
- Module:TableFish: see Template:FishTable for more details.
Usage[edit source]
-- Load data only once per page. (Do no use require())
local AnimalData = mw.loadData("Module:AnimalData")
-- Assert that some data was received, otherwise throw an error.
assert(AnimalData.animals, "Failed to load data from Module:AnimalData!")
-- You may then use data from this module in your script. For example:
local agoutiData = AnimalData.animals["Agouti"]
-- Or to iterate over the table, you can do this:
for animalName, data in pairs(AnimalData.animals) do
-- animalName now contains the name of the animal in English.
-- data is the data table for that animal.
end