Module:Parameter names example: Difference between revisions

m
(allow custom display values)
m (11 revisions imported from templatewiki:Module:Parameter_names_example)
 
(9 intermediate revisions by 6 users not shown)
Line 11:
local function italicize(s)
return "''" .. s .. "''"
end
 
local function plain(s)
return s
end
 
Line 18 ⟶ 22:
if args._display == 'italics' or args._display == 'italic' then
formatFunc = italicize
elseif args._display == 'plain' then
formatFunc = plain
else
formatFunc = makeParam
Line 32 ⟶ 38:
end
 
-- Find the template name and call it with the arguments.
local template
local template = args._template or mw.title.getCurrentTitle().basePageTitle.text
if args._template then
template = args._template
else
local templatecurrentTitle = args._template or mw.title.getCurrentTitle().basePageTitle.text
if currentTitle.prefixedText:find('/sandbox$') then
template = currentTitle.prefixedText
else
template = currentTitle.basePageTitle.prefixedText
end
end
 
-- Call the template with the arguments.
frame = frame or mw.getCurrentFrame()
local success, result = pcall(
return frame:expandTemplate{title = template, args = targs}
frame.expandTemplate,
frame,
return frame:expandTemplate {title = template, args = targs}
)
if success then
return result
else
return ''
end
end