Module:Parameter names example: Difference between revisions

use the current page instead of the base page if we are on a /sandbox subpage, and use pcall to expand the template in case there are any errors
(we should probably use the prefixedText for the template name for people who like making templates in funky namespaces)
(use the current page instead of the base page if we are on a /sandbox subpage, and use pcall to expand the template in case there are any errors)
Line 32:
end
 
-- Find the template name and call it with the arguments.
local template
local template = args._template or mw.title.getCurrentTitle().basePageTitle.prefixedText
if args._template then
template = args._template
else
local currentTitle = mw.title.getCurrentTitle()
if currentTitle.prefixedText:find('/sandbox$') then
template = currentTitle.prefixedText
else
local template = args._template or mw.title.getCurrentTitle()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.expantTemplate,
frame,
return frame:expandTemplate {title = template, args = targs}
)
if success then
return result
else
return ''
end
end
 
Anonymous user