Module:CountryData/doc
| This is a documentation subpage for Module:CountryData. It may contain usage information, categories and other content that is not part of the original module page. |
This module has three functions to extract data from country data templates, which are used for most flag templates.
gettable
Extracts all parameters from a data template and returns them as a Lua table. This function is only usable from other Lua modules; invoke it using data = require('Module:CountryData').gettable(parameters).
The first parameter is the frame of the invoking module; the second is the country or other entity to get the data of. The optional third parameter is a table of parameters to pass into the data template; for example, |age= or |mw=, which are used in the values of some sports alias parameters.
The function returns an empty table if a data template does not exist or does not conform to the standard structure.
getalias
If used from wikicode, this function returns the value of a single field in a data template. The first parameter is the country or other entity whose data to return; the second is the name of the field. For example, {{#invoke:CountryData|getalias|France|flag alias}} → Flag of France.svg.
Note: This is likely not quicker than wikicode-only alternatives such as {{getalias}}, {{getalias2}} and {{pst name}}, because it transcludes the data template from Lua and converts it to a Lua table using the above function, picks the wanted parameter name, and returns it to wikicode, whereas other templates perform two simple non-Lua transclusions to get the same result. The Lua version also doesn't let non-existing variant values fall back to the main ones like getalias and getalias2 do.
gettemplate
This function concatenates the fields of a data template into a string similar to what you get when transcluding it directly. It can be compared with a direct transclusion to test if a template is being converted to Lua correctly:
{{pre|{{Country data France}}}}
{{pre|{{#invoke:CountryData|gettemplate|France}}}}
gives
{{ {{{1}}}
| alias = France
| flag alias = Flag of France.svg
| flag alias-1790 = Flag of France (1790–1794).svg
| flag alias-1794 = Flag of France (1794–1815, 1830–1958).svg
| flag alias-1814 = Flag of the Kingdom of France (1814-1830).svg
| flag alias-1830 = Flag of France (1794–1815, 1830–1958).svg
| flag alias-1848 = Drapeau france 1848.svg
| flag alias-1848a = Drapeau france 1848.svg
| flag alias-1848b = Flag of France (1794–1815, 1830–1958).svg
| flag alias-1974 = Flag of France (lighter variant).svg
| flag alias-naval = Civil and Naval Ensign of France.svg
| flag alias-naval-1790 = Flag of French-Navy-Revolution.svg
| flag alias-air force = Flag of France.svg
| link alias-air force = French Air and Space Force
| flag alias-coast guard = French Maritime Gendarmerie racing stripe.svg
| border-coast guard =
| link alias-coast guard = French Maritime Gendarmerie
| flag alias-army = Flag of France.svg
| link alias-army = French Army
| link alias-naval = French Navy
| flag alias-navy = Civil and Naval Ensign of France.svg
| link alias-navy = French Navy
| size =
| name =
| altlink =
| variant =
}}
{{ {{{1}}}
| altlink =
| flag alias-naval-1790 = Flag of French-Navy-Revolution.svg
| link alias-coast guard = French Maritime Gendarmerie
| border-coast guard =
| flag alias-1848 = Drapeau france 1848.svg
| flag alias = Flag of France.svg
| variant =
| flag alias-1814 = Flag of the Kingdom of France (1814-1830).svg
| flag alias-1830 = Flag of France (1794–1815, 1830–1958).svg
| alias = France
| flag alias-1794 = Flag of France (1794–1815, 1830–1958).svg
| flag alias-army = Flag of France.svg
| flag alias-naval = Civil and Naval Ensign of France.svg
| flag alias-navy = Civil and Naval Ensign of France.svg
| flag alias-1848b = Flag of France (1794–1815, 1830–1958).svg
| name =
| size =
| flag alias-1848a = Drapeau france 1848.svg
| link alias-naval = French Navy
| flag alias-1974 = Flag of France (lighter variant).svg
| link alias-air force = French Air and Space Force
| link alias-army = French Army
| flag alias-coast guard = French Maritime Gendarmerie racing stripe.svg
| flag alias-1790 = Flag of France (1790–1794).svg
| flag alias-air force = Flag of France.svg
| link alias-navy = French Navy
}}
Note that, like with all Lua tables, the order of entries is not preserved, so the parameters are mixed up.