Template:$/doc: Difference between revisions

From RuneRealm Wiki
Jump to navigation Jump to search
Content added Content deleted
(Created page with "{{Documentation}} 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: <pre>{{$|param1=value|foo=bar|example=great}}</pre> {{$|param1=value|foo=bar|example=great}} ==Example== As an example, imagine a "Template:BigTable" which calls an associated "Module:BigTable": <syntaxhighlight> {{BigTable |{{$|metal1=bronze|metal2=iron|metal3=steel}} |{{$|metal1=mithril|metal2=ad...")
 
No edit summary
Tag: Reverted
Line 1: Line 1:
{{Documentation}}
{{Documentation}}
A template link with a variable number of parameters.


===Use===
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:
To use this for templates, use
:{{T|T|<nowiki>parameter 1|parameter 2|parameter 3|...|parameter 20</nowiki>}}<!-- self-referential examples! -->
To use other namespaces, use the namespace as prefix, for example
:{{T|T|User:Example}}
And to show transclusions of mainspace mw.pages, use
:{{T|T|:Bucket}}


===Example===
<pre>{{$|param1=value|foo=bar|example=great}}</pre>
<code><nowiki>{{T|Stub}}</nowiki></code>
{{$|param1=value|foo=bar|example=great}}
:{{T|Stub}}


<code><nowiki>{{T|Stub|Item1|Item2|Item3|Item4|Item5|...}}</nowiki></code>
==Example==
:{{T|Stub|Item1|Item2|Item3|Item4|Item5|...}}
As an example, imagine a "Template:BigTable" which calls an associated "Module:BigTable":


<includeonly>[[Category:Formatting templates|{{PAGENAME}}]]</includeonly>
<syntaxhighlight>
{{BigTable
|{{$|metal1=bronze|metal2=iron|metal3=steel}}
|{{$|metal1=mithril|metal2=adamant|metal3=rune}}
}}
</syntaxhighlight>

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:

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

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

<syntaxhighlight lang="lua">
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
</syntaxhighlight>

Revision as of 00:53, 17 October 2024

This is a documentation subpage for Template:$.
It contains usage information, categories, and other content that is not part of the original template page.
Template:$ invokes function serialize in Module:$ using Lua.

A template link with a variable number of parameters.

Use

To use this for templates, use

{{T|parameter 1|parameter 2|parameter 3|...|parameter 20}}

To use other namespaces, use the namespace as prefix, for example

{{T|User:Example}}

And to show transclusions of mainspace mw.pages, use

{{T|:Bucket}}

Example

{{T|Stub}}

{{Stub}}

{{T|Stub|Item1|Item2|Item3|Item4|Item5|...}}

{{Stub|Item1|Item2|Item3|Item4|Item5|...}}