Template:$: Difference between revisions

From RuneRealm Wiki
Jump to navigation Jump to search
Content added Content deleted
(Created page with "<includeonly>{{#invoke:$|serialize}}</includeonly><noinclude>{{/doc}}</noinclude>")
 
No edit summary
Tag: Reverted
Line 1: Line 1:
<includeonly>{{#invoke:$|serialize}}</includeonly><noinclude>{{/doc}}</noinclude>
<includeonly><span class="plainlinks">{{#invoke:T|main}}</span></includeonly><noinclude>{{/doc}}</noinclude>

Revision as of 00:48, 17 October 2024

Template documentation
This documentation is transcluded from Template:$/doc. [edit] [history] [purge]
Template:$ invokes function main in Module:T using Lua.

This template converts all provided template params and template values into key/value pairs, which it then passes through as a single json-style string:

{{$|param1=value|foo=bar|example=great}}

Lua error in Module:T at line 21: attempt to index local 'link' (a nil value).

Example

As an example, imagine a "Template:BigTable" which calls an associated "Module:BigTable":

{{BigTable
|{{$|metal1=bronze|metal2=iron|metal3=steel}}
|{{$|metal1=mithril|metal2=adamant|metal3=rune}}
}}

Template:$ serializes the information inside of it into a string of key/value pairs, effectively converting the information to this style as it passes through into Template:BigTable:

{{BigTable
|{"metal1":"bronze","metal2":"iron","metal3":"steel"}
|{"metal1":"mithril","metal2":"adamant","metal3":"rune"}
}}

To access the information in the json params, the module uses the deserialize command from Module:$ on the parameters. This converts the json strings into json objects with standard key/value pairs. The deserialize command leaves normal template params unchanged:

local ds = require('Module:$').deserialize
local p = {}

function p._main(args)
	local secondmetalfromfirstparam = args[1]['metal2']
	local thirdmetalfromsecondparam = args[2]['metal3']
end

function p.main(frame)
	local args = ds(frame:getParent().args)
	return p._main(args)
end

return p