Difference between revisions of "Module:Sandbox/BrandonXLF/1"

From blackwiki
Jump to navigation Jump to search
blackwiki>BrandonXLF
(Restored revision 883984777 by BrandonXLF (Restorer))
blackwiki>BrandonXLF
(This should work)
Line 1: Line 1:
local p = {}
+
function main (args1, args2, switch)  
function p.main (frame)
+
local template = args2['_']
local fA  = frame.args
+
args2._ = nil
local pA  = frame:getParent().args
+
if switch then
local tA = {}
+
args1, args2 = args2, args1
local template, pF = fA['_t'], require('Module:Yesno')(fA._pf)
+
end
fA._t, fA._pf = nil, nil
 
 
if not template then
 
if not template then
 
return require('Module:Error').error({'Error: no template name given.'})
 
return require('Module:Error').error({'Error: no template name given.'})
 
end
 
end
if pF then
+
for k,v in pairs(args1) do
fA, pA = pA, fA
+
args2[k] = v
 
end
 
end
for k,v in pairs(pA) do
+
return frame:expandTemplate{title = template, args = args2}
tA[k] = v
+
end
end
+
 
for k,v in pairs(fA) do
+
function gen (switch)
tA[k] = v
+
return function (frame)
 +
return main(frame:getParent().args, frame.args, switch)
 
end
 
end
return frame:expandTemplate{title = template, args = tA}
 
 
end
 
end
return p
+
 
 +
return {
 +
default = gen(false),
 +
force = gen(true)
 +
}

Revision as of 23:39, 4 January 2020

DO NOT DELETE

Module:Call calls a template while giving it all the arguments the current page receives. It is meant to be used in the template namespace and will only work in other namespaces if the page it's being used on is transcluded on another page.

Usage

There are two ways of using the module, using the default function and using the force function.

Set default values for parameters

{{#invoke:call|default|_=template}}

When using the default function, parameters supplied to the #invoke call will be overridden by parameters sent to the template calling this module.

Set forced values for parameters

{{#invoke:call|force|_=template}}

When using the force function, parameters supplied to the #invoke call will override parameters sent to the template calling this module.


function main (args1, args2, switch) 
	local template = args2['_']
	args2._ = nil
	if switch then
		args1, args2 = args2, args1
	end
	if not template then
		return require('Module:Error').error({'Error: no template name given.'})
	end
	for k,v in pairs(args1) do
		args2[k] = v
	end
	return frame:expandTemplate{title = template, args = args2}
end

function gen (switch)
	return function (frame)
		return main(frame:getParent().args, frame.args, switch)
	end
end

return {
	default = gen(false),
	force = gen(true)
}