Anonymous user
Module:Arguments/doc: Difference between revisions
From Mariopedia, a wiki on Mario, Yoshi, Wario, Donkey Kong, Super Smash Bros., and more!
Jump to navigationJump to search
add info about the frameOnly and parentOnly options
(add info on ref tags and known limitations, add type checking examples for the valueFunc option) |
(add info about the frameOnly and parentOnly options) |
||
Line 86:
-- Code for processing one argument
end,
frameOnly = true,
parentOnly = true,
parentFirst = true,
readOnly = true,
Line 179 ⟶ 181:
=== Frames and parent frames ===
Arguments in the <code>args</code> table can be passed from the current frame or from its parent frame at the same time. To understand what this means, it is easiest to give an example. Let's say that we have a module called <code>Module:ExampleArgs</code>. This module prints the first
{{cot|Module:ExampleArgs code}}
Line 194 ⟶ 196:
local first = args[1] or ''
local second = args[2] or ''
▲ return first .. ' ' .. second .. ' ' .. third
end
Line 202 ⟶ 203:
{{cob}}
<code>Module:ExampleArgs</code> is then called by <code>Template:ExampleArgs</code>, which contains the code <code><nowiki>{{#invoke:ExampleArgs|main|
Now if we were to call <code>Template:ExampleArgs</code>, the following would happen:
There are three options you can set to change this behaviour: <code>frameOnly</code>, <code>parentOnly</code> and <code>parentFirst</code>. If you set <code>frameOnly</code> then only arguments passed from the current frame will be accepted; if you set <code>parentOnly</code> then only only arguments passed from the parent frame will be accepted; and if you set <code>parentFirst</code> then arguments will be passed from both the current and parent frames, but the parent frame will have priority over the current frame. Here are the results in terms of <code>Template:ExampleArgs</code>:
* <code>frameOnly</code>
** <code><nowiki>{{ExampleArgs}}</nowiki></code> → firstInvokeArg
** <code><nowiki>{{ExampleArgs|firstTemplateArg}}</nowiki></code> → firstInvokeArg
parentFirst = true▼
** <code><nowiki>{{ExampleArgs|firstTemplateArg|secondTemplateArg}}</nowiki></code> → firstInvokeArg
* <code>parentOnly</code>
** <code><nowiki>{{ExampleArgs}}</nowiki></code> →
** <code><nowiki>{{ExampleArgs|firstTemplateArg}}</nowiki></code> → firstTemplateArg
** <code><nowiki>{{ExampleArgs|firstTemplateArg|secondTemplateArg}}</nowiki></code> → firstTemplateArg secondTemplateArg
** <code><nowiki>{{ExampleArgs}}</nowiki></code> → firstInvokeArg
** <code><nowiki>{{ExampleArgs|firstTemplateArg}}</nowiki></code> → firstTemplateArg
** <code><nowiki>{{ExampleArgs|firstTemplateArg|secondTemplateArg}}</nowiki></code> → firstTemplateArg secondTemplateArg
=== Writing to the args table ===
|