Title: Module:Template wrapper - freem URL Source: https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper Markdown Content: [Jump to content](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#bodyContent) - [x] Main menu Main menu move to sidebar hide Navigation * [Main page](https://freemwiki.com/wiki/Main_Page "Visit the main page [alt-shift-z]") * [Recent changes](https://freemwiki.com/wiki/Special:RecentChanges "A list of recent changes in the wiki [alt-shift-r]") * [Random page](https://freemwiki.com/wiki/Special:Random "Load a random page [alt-shift-x]") * [Help about MediaWiki](https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents) Legal * [Terms](https://freemwiki.com/wiki/Terms_of_Service) * [Privacy Policy](https://freemwiki.com/wiki/Privacy_Policy) * [About](https://freemwiki.com/wiki/About) * [Contact](https://freemwiki.com/wiki/Contact) [![Image 1](https://freemwiki.com/images/freem.svg)**freem**](https://freemwiki.com/wiki/Main_Page) [Search](https://freemwiki.com/wiki/Special:Search "Search freem [alt-shift-f]") Search - [x] Appearance * [Create account](https://freemwiki.com/index.php?title=Special:CreateAccount&returnto=Module%3ATemplate+wrapper&returntoquery=oldid%3D579809 "You are encouraged to create an account and log in; however, it is not mandatory") * [Log in](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3ATemplate+wrapper&returntoquery=oldid%3D579809 "You are encouraged to log in; however, it is not mandatory [alt-shift-o]") - [x] Personal tools * [Create account](https://freemwiki.com/index.php?title=Special:CreateAccount&returnto=Module%3ATemplate+wrapper&returntoquery=oldid%3D579809 "You are encouraged to create an account and log in; however, it is not mandatory") * [Log in](https://freemwiki.com/index.php?title=Special:UserLogin&returnto=Module%3ATemplate+wrapper&returntoquery=oldid%3D579809 "You are encouraged to log in; however, it is not mandatory [alt-shift-o]") Pages for logged out editors [learn more](https://freemwiki.com/wiki/Help:Introduction) * [Contributions](https://freemwiki.com/wiki/Special:MyContributions "A list of edits made from this IP address [alt-shift-y]") * [Talk](https://freemwiki.com/wiki/Special:MyTalk "Discussion about edits from this IP address [alt-shift-n]") # Module:Template wrapper - [x] Add languages * [Module](https://freemwiki.com/wiki/Module:Template_wrapper "View the module page [alt-shift-c]") * [Discussion](https://freemwiki.com/index.php?title=Module_talk:Template_wrapper&action=edit&redlink=1 "Discussion about the content page (page does not exist) [alt-shift-t]") - [x] English * [Read](https://freemwiki.com/wiki/Module:Template_wrapper) * [Edit source](https://freemwiki.com/index.php?title=Module:Template_wrapper&action=edit&oldid=579809 "Edit the source code of this page [alt-shift-e]") * [View history](https://freemwiki.com/index.php?title=Module:Template_wrapper&action=history "Past revisions of this page [alt-shift-h]") - [x] Tools Tools move to sidebar hide Actions * [Read](https://freemwiki.com/wiki/Module:Template_wrapper) * [Edit source](https://freemwiki.com/index.php?title=Module:Template_wrapper&action=edit&oldid=579809 "Edit the source code of this page [alt-shift-e]") * [View history](https://freemwiki.com/index.php?title=Module:Template_wrapper&action=history) General * [What links here](https://freemwiki.com/wiki/Special:WhatLinksHere/Module:Template_wrapper "A list of all wiki pages that link here [alt-shift-j]") * [Related changes](https://freemwiki.com/wiki/Special:RecentChangesLinked/Module:Template_wrapper "Recent changes in pages linked from this page [alt-shift-k]") * [Special pages](https://freemwiki.com/wiki/Special:SpecialPages "A list of all special pages [alt-shift-q]") * [Printable version](javascript:print(); "Printable version of this page [alt-shift-p]") * [Permanent link](https://freemwiki.com/index.php?title=Module:Template_wrapper&oldid=579809 "Permanent link to this revision of this page") * [Page information](https://freemwiki.com/index.php?title=Module:Template_wrapper&action=info "More information about this page") Appearance move to sidebar hide Text * Small Standard Large This page always uses small font size Width * Standard Wide The content is as wide as possible for your browser window. From freem Revision as of 21:11, 21 October 2022 by [en>Legoktm](https://freemwiki.com/wiki/User:Legoktm "en:User:Legoktm")(Replace [Module:No globals](https://freemwiki.com/index.php?title=Module:No_globals&action=edit&redlink=1 "Module:No globals (page does not exist)") with require( "strict" )) (diff) ← Older revision | [Latest revision](https://freemwiki.com/wiki/Module:Template_wrapper "Module:Template wrapper") ([diff](https://freemwiki.com/index.php?title=Module:Template_wrapper&diff=cur&oldid=579809 "Module:Template wrapper")) | [Newer revision →](https://freemwiki.com/index.php?title=Module:Template_wrapper&direction=next&oldid=579809 "Module:Template wrapper") ([diff](https://freemwiki.com/index.php?title=Module:Template_wrapper&diff=next&oldid=579809 "Module:Template wrapper")) _Documentation for this module may be created at [Module:Template wrapper/doc](https://freemwiki.com/index.php?title=Module:Template\_wrapper/doc&action=edit&redlink=1 "Module:Template wrapper/doc (page does not exist)")_ [](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-1)require('strict');[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-2)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-3)local error_msg = '|_template= missing or empty';[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-4)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-5)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-6)--[[--------------------------< I S _ I N _ T A B L E >--------------------------------------------------------[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-7)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-8)scan through tbl looking for value; return true if found, false else[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-9)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-10)]][](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-11)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-12)local function is_in_table (tbl, value)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-13) for k, v in pairs (tbl) do[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-14) if v == value then return true end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-15) end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-16) return false;[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-17)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-18)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-19)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-20)--[[--------------------------< A D D _ P A R A M E T E R >----------------------------------------------------[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-21)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-22)adds parameter name and its value to args table according to the state of boolean list argument; kv pair for[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-23)template execution; k=v string for template listing.[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-24)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-25)]][](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-26)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-27)local function add_parameter (k, v, args, list)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-28)if list then[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-29)table.insert( args, table.concat ({k, '=', v}));-- write parameter names and values to args table as string[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-30)else[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-31)args[k] = v;-- copy parameters to args table[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-32)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-33)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-34)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-35)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-36)--[[--------------------------< A L I A S _ M A P _ G E T >----------------------------------------------------[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-37)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-38)returns a table of local template (parent frame) parameter names and the target template names that match where[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-39)in [key]= pairs where:[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-40) [key] is local template parameter name (an alias)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-41) is target template parameter name (the canonical parameter name used in the working template)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-42)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-43)The parameter |_alias-map= has the form:[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-44) |_alias-map=[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-45)where is a comma-separated list of alias / canonical parameter name pairs in the form[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-46) : [](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-47)where:[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-48) is the local template's parameter name (alias)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-49) is the target template's parameter name (canonical)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-50) for enumerated parameters place an octothorp (#) where the enumerator digits are placed in the parameter names:[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-51) : [](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-52)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-53)]][](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-54)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-55)local function alias_map_get (_alias_map)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-56)local T = mw.text.split (_alias_map, '%s*,%s*');-- convert the comma-separated list into a table of alias pairs[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-57)local mapped_aliases = {};-- mapped aliases will go here[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-58)local l_name, t_name;-- parameter names[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-59)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-60)for _, alias_pair in ipairs (T) do-- loop through the table of alias pairs[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-61)l_name, t_name = alias_pair:match ('(.-)%s*:%s*(.+)');-- from each pair, get local and target parameter names[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-62)if l_name and t_name then-- if both are set[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-63)if tonumber (l_name) then[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-64)l_name = tonumber (l_name);-- convert number-as-text to a number[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-65)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-66)mapped_aliases[l_name] = t_name;-- add them to the map table[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-67)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-68)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-69)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-70)return mapped_aliases;[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-71)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-72)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-73)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-74)--[[--------------------------< F R A M E _ A R G S _ G E T >--------------------------------------------------[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-75)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-76)Fetch the wrapper template's 'default' and control parameters; adds default parameters to args[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-77)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-78)returns content of |_template= parameter (name of the working template); nil else[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-79)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-80)]][](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-81)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-82)local function frame_args_get (frame_args, args, list)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-83)local template;[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-84)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-85)for k, v in pairs (frame_args) do-- here we get the wrapper template's 'default' parameters[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-86)if 'string' == type (k) and (v and ('' ~= v)) then-- do not pass along positional or empty parameters[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-87)if '_template' == k then[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-88)template = v;-- save the name of template that we are wrapping[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-89)elseif '_exclude' ~= k and '_reuse' ~= k and '_include-positional' ~= k and '_alias-map' ~= k then-- these already handled so ignore here; [](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-90)add_parameter (k, v, args, list);-- add all other parameters to args in the style dictated by list[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-91)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-92)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-93)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-94)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-95)return template;-- return contents of |_template= parameter[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-96)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-97)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-98)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-99)--[=[--------------------------< P F R A M E _ A R G S _ G E T >------------------------------------------------[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-100)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-101)Fetches the wrapper template's 'live' parameters; adds live parameters that aren't members of the exclude table to[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-102)args table; positional parameters may not be excluded[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-103)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-104)no return value[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-105)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-106)]=][](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-107)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-108)local function pframe_args_get (pframe_args, args, exclude, _include_positional, list)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-109)for k, v in pairs (pframe_args) do[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-110)if 'string' == type (k) and not is_in_table (exclude, k) then-- do not pass along excluded parameters[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-111)if v and ('' ~= v) then-- pass along only those parameters that have assigned values[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-112)if 'unset' == v:lower() then-- special keyword to unset 'default' parameters set in the wrapper template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-113)v = '';-- unset the value in the args table[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-114)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-115)add_parameter (k, v, args, list)-- add all other parameters to args in the style dictated by list; alias map only supported for local-template parameters[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-116)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-117)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-118)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-119)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-120)if _include_positional then[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-121)for i, v in ipairs (pframe_args) do-- pass along positional parameters[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-122)if 'unset' == v:lower() then-- special keyword to unset 'default' parameters set in the wrapper template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-123)v = '';-- unset the value in the args table[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-124)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-125)add_parameter (i, v, args, list);[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-126)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-127)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-128)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-129)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-130)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-131)--[[--------------------------< _ M A I N >--------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-132)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-133)Collect the various default and live parameters into args styled according to boolean list.[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-134)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-135)returns name of the working or listed template or nil for an error message[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-136)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-137)]][](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-138)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-139)local function _main (frame, args, list)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-140)local template;[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-141)local exclude = {};-- table of parameter names for parameters that are not passed to the working template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-142)local reuse_list = {};-- table of pframe parameter names whose values are modified before they are passed to the working template as the same name[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-143)local alias_map = {};-- table that maps parameter aliases to working template canonical parameter names[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-144)local _include_positional;[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-145)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-146)if frame.args._exclude and ('' ~= frame.args._exclude) then-- if there is |_exclude= and it's not empty[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-147)exclude = mw.text.split (frame.args._exclude, "%s*,%s*");-- make a table from its contents[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-148)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-149)-- TODO: |_reuse= needs a better name (|_reuse=)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-150)if frame.args._reuse and ('' ~= frame.args._reuse) then-- if there is |_reuse= and it's not empty[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-151)reuse_list = mw.text.split (frame.args._reuse, "%s*,%s*");-- make a table from its contents[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-152)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-153)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-154)if frame.args['_alias-map'] and ('' ~= frame.args['_alias-map']) then-- if there is |_alias-map= and it's not empty[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-155)alias_map = alias_map_get (frame.args['_alias-map']);-- make a table from its contents[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-156)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-157)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-158)template = frame_args_get (frame.args, args, list);-- get parameters provided in the {{#invoke:template wrapper|...|...}}[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-159)if nil == template or '' == template then-- this is the one parameter that is required by this module[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-160)return nil;-- not present, tell calling function to emit an error message[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-161)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-162)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-163)_include_positional = 'yes' == frame.args['_include-positional'];-- when true pass all positional parameters along with non-excluded named parameters to ...[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-164)-- ... the working template; positional parameters are not excludable[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-165)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-166)local _pframe_args = frame:getParent().args;-- here we get the wrapper template's 'live' parameters from pframe.args[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-167)local pframe_args = {};-- a local table that we can modify[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-168)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-169)for k, v in pairs (_pframe_args) do-- make a copy that we can modify[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-170)pframe_args[k] = v;[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-171)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-172)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-173)-- here we look for pframe parameters that are aliases of canonical parameter names; when found[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-174)-- we replace the alias with the canonical. We do this here because the reuse_list works on[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-175)-- canonical parameter names so first we convert alias parameter names to canonical names and then[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-176)-- we remove those canonical names from the pframe table that are reused (provided to the working[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-177)-- template through the frame args table)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-178)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-179)for k, v in pairs (alias_map) do-- k is alias name, v is canonical name[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-180)if pframe_args[k] then-- if pframe_args has parameter with alias name[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-181)pframe_args[v] = _pframe_args[k];-- create new canonical name with alias' value[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-182)pframe_args[k] = nil;-- unset the alias[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-183)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-184)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-185)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-186)for k, v in pairs (pframe_args) do-- do enumerated parameter alias -> canonical translation[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-187)if 'string' == type (k) then-- only named parameters can be enumerated[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-188)if alias_map[k..'#'] then-- non-enumerated alias matches enumerated parameter pattern? enumerator at end only[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-189)pframe_args[alias_map[k..'#']:gsub('#', '')] = v;-- remove '#' and copy parameter to pframe_args table[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-190)pframe_args[k] = nil;-- unset the alias[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-191)elseif k:match ('%d+') then-- if this parameter name contains digits[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-192)local temp = k:gsub ('%d+', '#');-- make a copy; digits replaced with single '#'[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-193)local enum = k:match ('%d+');-- get the enumerator[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-194)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-195)if alias_map[temp] then-- if this parameter is a recognized enumerated alias[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-196)pframe_args[alias_map[temp]:gsub('#', enum)] = v;-- use canonical name and replace '#' with enumerator and add to pframe_args[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-197)pframe_args[k] = nil;-- unset the alias[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-198)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-199)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-200)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-201)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-202)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-203)-- pframe parameters that are _reused are 'reused' have the form something like this:[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-204)-- |chapter=[[wikisource:{{{[chapter](https://freemwiki.com/wiki/Template:Chapter "Template:Chapter")}}}|{{{[chapter](https://freemwiki.com/wiki/Template:Chapter "Template:Chapter")}}}]][](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-205)-- where a parameter in the wrapping template is modified and then passed to the working template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-206)-- using the same parameter name (in this example |chapter=)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-207)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-208)-- remove parameters that will be reused[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-209)for k, v in ipairs (reuse_list) do-- k is numerical index, v is canonical parameter name to ignore[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-210)if pframe_args[v] then-- if pframe_args has parameter that should be ignored[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-211)pframe_args[v] = nil;-- unset the ignored parameter[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-212)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-213)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-214)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-215)pframe_args_get (pframe_args, args, exclude, _include_positional, list);-- add parameters and values to args that are not listed in the exclude table[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-216)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-217)return template;-- args now has all default and live parameters, return working template name[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-218)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-219)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-220)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-221)--[[--------------------------< W R A P >----------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-222)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-223)Template entry point. Call this function to 'execute' the working template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-224)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-225)]][](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-226)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-227)local function wrap (frame)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-228)local args = {};-- table of default and live parameters and their values to be passed to the wrapped template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-229)local template;-- the name of the working template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-230)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-231)template = _main (frame, args, false);-- get default and live parameters and the name of the working template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-232)if not template then-- template name is required[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-233)return error_msg;-- emit error message and abandon if template name not present[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-234)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-235)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-236)return frame:expandTemplate {title=template, args=args};-- render the working template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-237)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-238)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-239)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-240)--[[--------------------------< L I S T >----------------------------------------------------------------------[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-241)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-242)Template entry point. Call this function to 'display' the source for the working template. This function added[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-243)as a result of a TfD here: Wikipedia:Templates_for_discussion/Log/2018_April_28#Module:PassArguments[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-244)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-245)This function replaces a similarly named function which was used in {{[cite compare](https://freemwiki.com/wiki/Template:Cite_compare "Template:Cite compare")}} and {{[cite compare2](https://freemwiki.com/wiki/Template:Cite_compare2 "Template:Cite compare2")}}[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-246)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-247)Values in the args table are numerically indexed strings in the form 'name=value'[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-248)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-249)]][](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-250)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-251)local function list(frame, do_link)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-252)local args = {};-- table of default and live parameters and their values to be passed to the listed template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-253)local template;-- the name of the listed template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-254)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-255)template = _main (frame, args, true);-- get default and live parameters and the name of the listed template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-256)if not template then-- template name is required[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-257)return error_msg;-- emit error message and abandon if template name not present[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-258)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-259)if do_link then[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-260)template = ('[[%s|%s]]'):format(frame:expandTemplate{ title='Transclude', args = {template} }, template)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-261)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-262)table.sort(args)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-263)for i = 1, #args do[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-264)local stripped = args[i]:match('^' .. i .. '=([^=]*)$')[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-265)if stripped then args[i] = stripped else break end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-266)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-267)return frame:preprocess(table.concat({[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-268)'{{',[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-269)template,[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-270)('|%s'):rep(#args):format(unpack(args)), '}}'}));-- render the template[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-271)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-272)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-273)local function link (frame)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-274)return list(frame, true)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-275)end[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-276)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-277)--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-278)]][](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-279)[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-280)return {[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-281)link = link,[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-282)list = list,[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-283)wrap = wrap,[](https://freemwiki.com/index.php?oldid=579809&title=Module%3ATemplate_wrapper#L-284)}; Retrieved from "[https://freemwiki.com/index.php?title=Module:Template_wrapper&oldid=579809](https://freemwiki.com/index.php?title=Module:Template_wrapper&oldid=579809)" * This page was last edited on 21 October 2022, at 21:11. * Content is available under [Creative Commons Attribution-ShareAlike 4.0](https://creativecommons.org/licenses/by-sa/4.0/) unless otherwise noted. FreemWiki is operated by **FINGERPOWER DIGITAL TECHNOLOGY LLC** (Colorado, Entity ID 20221978727). * [Privacy Policy](https://freemwiki.com/wiki/Privacy_Policy) * [About](https://freemwiki.com/wiki/About) * [Terms of Service](https://freemwiki.com/wiki/Terms_of_Service) * [Mobile view](https://freemwiki.com/index.php?title=Module:Template_wrapper&oldid=579809&mobileaction=toggle_view_mobile)