Module:Sandbox/Nbound/infobox Australian road/State
Appearance
local p = {}
function p.State(frame)
local pframe = frame:getParent()
local config = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
local args = pframe.args -- the arguments passed TO the template, in the wikitext that transcludes the template
local statecheck = config[1] -- check if first or second state
local state -- initialise variable
if statecheck == "State1" then
state = args["state"] or "" -- get state
else
state = args["state2"] or "" -- get state (2nd state)
end
local linkpass = state -- create untouched variable to pass wikitext link (if needed)
state = string.lower(state) -- change state to lower case
local links = {act = "[[Australian Capital Territory]]", jbt = "[[Jervis Bay Territory]]", nsw = "[[New South Wales]]", nt = "[[Northern Territory]]", qld = "[[Queensland]]",
sa = "[[South Australia]]", tas = "[[Tasmania]]", vic = "[[Victoria (Australia)|Victoria]]", wa = "[[Western Australia]]"}
if statecheck == "State1" then
return links[state] or linkpass or nil -- if first state no need for dash
elseif state == "" then
return nil --return nil for 2nd state if none exists (first state is handled in code above, but code below cannot concatenate a null value)
elseif links[state] then
return " – " .. links[state] -- return premade link if not a wikitext link
else
return " – " .. linkpass -- return wikitext link if all else fails
end
end
return p