“模块:Yesno”与“模板:Tlx”:页面之间的差异

来自NebulaeWiki
(页面间差异)
(已保护“模块:Yesno”([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期)))
 
(已保护“模板:Tlx”([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期)))
 
第1行: 第1行:
-- Function allowing for consistent treatment of boolean-like wikitext input.
<span class="nowrap"><code><nowiki>{{</nowiki>[[Template:{{{1}}}|{{{1}}}]]{{t/piece|{{{2|---}}}}}{{t/piece|{{{3|---}}}}}{{t/piece|{{{4|---}}}}}{{t/piece|{{{5|---}}}}}{{t/piece|{{{6|---}}}}}{{t/piece|{{{7|---}}}}}{{t/piece|{{{8|---}}}}}{{t/piece|{{{9|---}}}}}{{t/piece|{{{10|---}}}}}{{t/piece|{{{11|---}}}}}{{t/piece|{{{12|---}}}}}{{t/piece|{{{13|---}}}}}{{t/piece|{{{14|---}}}}}{{t/piece|{{{15|---}}}}}{{t/piece|{{{16|---}}}}}{{t/piece|{{{17|---}}}}}{{t/piece|{{{18|---}}}}}{{t/piece|{{{19|---}}}}}{{t/piece|{{{20|---}}}}}{{t/piece|{{{21|---}}}}}<nowiki>}}</nowiki></code></span><noinclude>
-- It works similarly to the template {{yesno}}.


return function (val, default)
{{/doc}}
-- 如果你的维基使用非ASCII字符来表示 "是"、"否 "等等
<!-- Add categories and interwikis to the /doc subpage, not here! -->
-- 你应该在下面一行用 "mw.ustring.lower(val) "替换 "val:lower()"。
</noinclude>
val = type(val) == 'string' and mw.ustring.lower(val) or val
if val == nil then
return nil
elseif val == true
or val == '是'
or val == 'yes'
or val == 'y'
or val == 'true'
or val == 't'
or tonumber(val) == 1
then
return true
elseif val == false
or val == '否'
or val == 'no'
or val == 'n'
or val == 'false'
or val == 'f'
or tonumber(val) == 0
then
return false
else
return default
end
end

2023年9月23日 (六) 22:33的最新版本

{{[[Template:{{{1}}}|{{{1}}}]]}}


This template is used to show example template usage without expanding the template itself.

Basic use

(Note: In the following examples, ellipses (groups of three dots) indicate where parameters have been omitted.)

{{tlx|<Template>|<first parameter>|<second parameter>|<third>|<...>|<twentieth>}} produces: {{Template|<first parameter>|<second parameter>|<third>|<...>|<twentieth>}}

Where parameters might contain one or more equals-signs ("="), replace each equals-sign with 模板:Tlf:

{{tlx|<Template>|<first{{=}}something>|<second>|<third{{=}}something>|<...>|<twentieth>}} produces: {{Template|<first=something>|<second>|<third=something>|<...>|<twentieth>}}

For more than ten parameters, possibly also containing equals-signs, use <nowiki>...</nowiki> thus:

{{tlx|<Template>|<<nowiki>''first''|''second''|''third=something''|...|''999th''</nowiki>>}} produces: {{Template|<first|second|third=something|...|999th>}}


See also