Difference between revisions of "Module:ATC code to template name"
Jump to navigation
Jump to search
blackwiki>Berchanhimez (test) |
blackwiki>Berchanhimez (test) |
||
| Line 18: | Line 18: | ||
for k,v in pairs(p.lookuptable) do | for k,v in pairs(p.lookuptable) do | ||
if v.code == input then | if v.code == input then | ||
| − | p. | + | p.nameoftemplate = v.template |
| + | p.out = frame:expandTemplate{ title = p.nameoftemplate } | ||
end | end | ||
end | end | ||
| Line 24: | Line 25: | ||
error("None") | error("None") | ||
end | end | ||
| − | |||
return p.out | return p.out | ||
end | end | ||
return p | return p | ||
Revision as of 07:10, 5 July 2020
Translates an ATC code passed as an unnamed parameter to the function "translate" into the name of the navbox template associated with that ATC code on Wikipedia.
Use:
{{#invoke:ATC code to template name|translate|X00}}
The template returned does not have the Template: prefix.
-- this module provides a lookup from ATC codes to their associated navbox templates --
p = {}
local frame = mw.getCurrentFrame()
local input = tostring(frame.args[1])
p.lookuptable = {
{ code="A01", template="Stomatological preparations",},
{ code="A02A", template="Antacids", },
{ code="A02B", template="Drugs for peptic ulcer and GORD", },
{ code="A03", template="Drugs for functional gastrointestinal disorders", },
{ code="A04", template="Antiemetics", },
}
function p.translate ()
for k,v in pairs(p.lookuptable) do
if v.code == input then
p.nameoftemplate = v.template
p.out = frame:expandTemplate{ title = p.nameoftemplate }
end
end
if p.out == nil then
error("None")
end
return p.out
end
return p