如何在 mediawiki 中的 #if 值中使用参数?
How do I use a parameter in an #if value in mediawiki?
我正在尝试创建一个 mediawiki 模板:
|-
| {{{name}}}{{#if:{{{ref|}}}|<ref>{{{ref}}}</ref>|}}{{#if:{{{ndb|}}}|<ref>https://ndb.nal.usda.gov/ndb/foods/show/{{{ndb}}}</ref>|}} || {{{size|--}}} || {{{carbs|--}}} || {{{sugar|--}}} || {{{fiber|--}}} || {{{fat|--}}} || {{{protein|--}}}
大部分工作正常,但如果我传递 ref
或 ndb
参数,#if
无法正常工作,我会得到
<ref>{{{ref}}}</ref>
或
<ref>https://ndb.nal.usda.gov/ndb/foods/show/{{{ndb}}}</ref>
我没有得到我期望的结果:
<ref>http://the.passed.value/</ref>
或
<ref>https://ndb.nal.usda.gov/ndb/foods/show/passed_value</ref>
#if
似乎不是问题的原因。原因是 <ref>
没有按照您期望的顺序处理。您需要 #tag
在稍后的模板处理阶段生成解析器或扩展标记:
Template:Google
源代码:
<includeonly><!--
-->{{#if: {{{ref|}}}
| {{#tag: ref |{{{ref}}}}}
}}<!--
-->{{#if: {{{q|}}}
| {{#tag: ref |[https://google.com/search?q={{#urlencode:{{{q}}}}} Google: {{{q}}}]}}
}}<!--
--></includeonly>
页面源代码:
{{Google
| ref = http://google.com/search?q=foo+bar
| q = foo bar
}}
<references/>
页面输出:
[1][2]
我正在尝试创建一个 mediawiki 模板:
|-
| {{{name}}}{{#if:{{{ref|}}}|<ref>{{{ref}}}</ref>|}}{{#if:{{{ndb|}}}|<ref>https://ndb.nal.usda.gov/ndb/foods/show/{{{ndb}}}</ref>|}} || {{{size|--}}} || {{{carbs|--}}} || {{{sugar|--}}} || {{{fiber|--}}} || {{{fat|--}}} || {{{protein|--}}}
大部分工作正常,但如果我传递 ref
或 ndb
参数,#if
无法正常工作,我会得到
<ref>{{{ref}}}</ref>
或
<ref>https://ndb.nal.usda.gov/ndb/foods/show/{{{ndb}}}</ref>
我没有得到我期望的结果:
<ref>http://the.passed.value/</ref>
或
<ref>https://ndb.nal.usda.gov/ndb/foods/show/passed_value</ref>
#if
似乎不是问题的原因。原因是 <ref>
没有按照您期望的顺序处理。您需要 #tag
在稍后的模板处理阶段生成解析器或扩展标记:
Template:Google
源代码:
<includeonly><!--
-->{{#if: {{{ref|}}}
| {{#tag: ref |{{{ref}}}}}
}}<!--
-->{{#if: {{{q|}}}
| {{#tag: ref |[https://google.com/search?q={{#urlencode:{{{q}}}}} Google: {{{q}}}]}}
}}<!--
--></includeonly>
页面源代码:
{{Google
| ref = http://google.com/search?q=foo+bar
| q = foo bar
}}
<references/>
页面输出:
[1][2]