Template:$/doc: Difference between revisions

no edit summary
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
 
Line 1:
{{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:
The '''*''' template is used to add bullets (example: '''&bull;''') by substituting <tt><nowiki>'''&amp;bull;'''</nowiki></tt> automatically.
 
<pre>{{$|param1=value|foo=bar|example=great}}</pre>
==Usage==
{{$|param1=value|foo=bar|example=great}}
The recommended usage is to use spaces ''before'' and ''after'' the template.
<pre>[[Bones]] {{*}} [[Big bones]]</pre>
 
==Example==
The template renders one space on each side of the bullet.
As an example, imagine a "Template:BigTable" which calls an associated "Module:BigTable":
[[Bones]] {{*}} [[Big bones]]
 
<syntaxhighlight>
For long dotted lists each list item can be put on its own line, with spaces between each item and the template.
{{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:
<pre>
[[Bones]] {{*}}
[[Bat bones]] {{*}}
[[Wolf bones]] {{*}}
[[Big bones]] {{*}}
[[Dragon bones]]
</pre>
 
<syntaxhighlight>
As before, the template renders one space on each side of the bullets.
{{BigTable
[[Bones]] {{*}}
|{"metal1":"bronze","metal2":"iron","metal3":"steel"}
[[Bat bones]] {{*}}
|{"metal1":"mithril","metal2":"adamant","metal3":"rune"}
[[Wolf bones]] {{*}}
}}
[[Big bones]] {{*}}
</syntaxhighlight>
[[Dragon bones]]
 
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:
When the list is too long and line breaks, the class "nowraplinks" should be used.
 
<syntaxhighlight lang="lua">
<pre style="width:95%; overflow:scroll"><div class="nowraplinks">
local ds = require('Module:$').deserialize
[[Bones]] {{*}} [[Bat bones]] {{*}} [[Wolf bones]] {{*}} [[Big bones]] {{*}} [[Dragon bones]] {{*}} [[Bones]] {{*}} [[Bat bones]] {{*}} [[Wolf bones]] {{*}} [[Big bones]] {{*}} [[Dragon bones]] {{*}} [[Bones]] {{*}} [[Bat bones]] {{*}} [[Wolf bones]] {{*}} [[Big bones]] {{*}} [[Dragon bones]]
local p = {}
</div></pre>
 
function p._main(args)
Using "nowraplinks" forces the line break to come after one of the bullets.
local secondmetalfromfirstparam = args[1]['metal2']
local thirdmetalfromsecondparam = args[2]['metal3']
end
 
function p.main(frame)
<div class="nowraplinks">
local args = ds(frame:getParent().args)
[[Bones]] {{*}} [[Bat bones]] {{*}} [[Wolf bones]] {{*}} [[Big bones]] {{*}} [[Dragon bones]] {{*}} [[Bones]] {{*}} [[Bat bones]] {{*}} [[Wolf bones]] {{*}} [[Big bones]] {{*}} [[Dragon bones]] {{*}} [[Bones]] {{*}} [[Bat bones]] {{*}} [[Wolf bones]] {{*}} [[Big bones]] {{*}} [[Dragon bones]]
return p._main(args)
</div>
end
 
return p
<includeonly>[[Category:Formatting templates|{{PAGENAME}}]]</includeonly>
</syntaxhighlight>
 
{{TemplateData|<templatedata>
{
"params": {},
"description": "The * template is used to add bullets (example: •) by substituting '''&bull;''' automatically.",
"format": "inline"
</templatedata>
}}