Template:Yesno: Difference between revisions

From Funkinchan
Jump to navigationJump to search
(making template)
 
(making template)
 
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)
|f
-- If your wiki uses non-ascii characters for any of "yes", "no", etc., you
|false
-- should replace "val:lower()" with "mw.ustring.lower(val)" in the
|off
-- following line.
|0        = {{{no|<!-- null -->}}}
val = type(val) == 'string' and val:lower() or val
|        = {{{blank|{{{no|<!-- null -->}}}}}}
if val == nil then
|¬        = {{{¬|}}}
return nil
|yes
elseif val == true
|y
or val == 'yes'
|t
or val == 'y'
|true
or val == 'true'
|on
or val == 't'
|1       = {{{yes|yes}}}
or val == 'on'
|#default = {{{def|{{{yes|yes}}}}}}
or tonumber(val) == 1
}}<noinclude>
then
{{Documentation}}
return true
</noinclude>
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

Latest revision as of 04:11, 19 September 2023