Module:Template wrapper: Difference between revisions

From Frontierpedia, the Microsoft Agent encyclopedia
en>Trappist the monk
m (Trappist the monk moved page Module:Sandbox/trappist the monk/cs1 wrapper to Module:Citation/CS1/Wrapper without leaving a redirect: move out of sandbox;)
en>Trappist the monk
(unset keyword to unset default parameters; ignore parameters without values;)
Line 21: Line 21:
local pframe = frame:getParent(); -- here we get the wrapper template's 'live' parameters
local pframe = frame:getParent(); -- here we get the wrapper template's 'live' parameters
for k, v in pairs (pframe.args) do
for k, v in pairs (pframe.args) do
args[k] = v; -- copy parent frame parameters to args table
if v and v ~= '' then -- pass along only those parameters that have assigned values
if 'unset' == v:lower() then -- special keyword to unset 'default' parameters set in the wrapper template
v = ''; -- unset the value
end
args[k] = v; -- copy parent frame parameters to args table
end
end
end

Revision as of 12:53, 8 January 2018

Documentation for this module may be created at Module:Template wrapper/doc

require('Module:No globals');

local p={};

function p.cs1_wrapper (frame)
	local args = {};
	local template;
	
	for k, v in pairs (frame.args) do											-- here we get the wrapper template's 'default' parameters
		if 'template' == k then
			template = v;														-- save the name of template that we are wrapping
		else
			args[k] = v;														-- copy frame parameters to args table
		end
	end
	
	if nil == template or '' == template then									-- this is the one parameter required by this module
		return '<span style=\"font-size:100%\" class=\"error\"><code style=\"color:inherit; border:inherit; padding:inherit;\">&#124;template=</code> missing or empty</span>';
	end

	local pframe = frame:getParent();											-- here we get the wrapper template's 'live' parameters
	for k, v in pairs (pframe.args) do
		if v and v ~= '' then													-- pass along only those parameters that have assigned values
			if 'unset' == v:lower() then										-- special keyword to unset 'default' parameters set in the wrapper template
				v = '';															-- unset the value
			end
			args[k] = v;														-- copy parent frame parameters to args table
		end
	end
	
	return frame:expandTemplate {title=template, args=args};					-- render the citation
end

return p;