Difference between revisions of "Template:Yesno"

m (1 revision imported)
(add support for on/off, per discussion)
(One intermediate revision by one other user not shown)
Line 1: Line 1:
-- Function allowing for consistent treatment of boolean-like wikitext input.
+
{{<includeonly>safesubst:</includeonly>#switch: {{<includeonly>safesubst:</includeonly>lc: {{{1|¬}}} }}
-- It works similarly to the template {{yesno}}.
+
|no
 
+
|n
return function (val, default)
+
|false
-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you
+
|off
-- should replace "val:lower()" with "mw.ustring.lower(val)" in the
+
|0        = {{{no|<!-- null -->}}}
-- following line.
+
|        = {{{blank|{{{no|<!-- null -->}}}}}}
val = type(val) == 'string' and val:lower() or val
+
|¬        = {{{¬|}}}
if val == nil then
+
|yes
return nil
+
|y
elseif val == true
+
|true
or val == 'yes'
+
|on
or val == 'y'
+
|1       = {{{yes|yes}}}
or val == 'true'
+
|#default = {{{def|{{{yes|yes}}}}}}
or val == 't'
+
}}<noinclude>
or val == 'on'
+
{{Documentation}}
or tonumber(val) == 1
+
</noinclude>
then
 
return true
 
elseif val == false
 
or val == 'no'
 
or val == 'n'
 
or val == 'false'
 
or val == 'f'
 
or val == 'off'
 
or tonumber(val) == 0
 
then
 
return false
 
else
 
return default
 
end
 
end
 

Revision as of 08:37, 23 January 2018

{{#switch: ¬

|no
|n
|false
|off
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|on
|1        = yes
|#default = yes

}} {{#switch:<translate></translate> | = Lua error: Internal error: The interpreter exited with status 127. | #default=

 Script error: No such module "Template translation".

}}