查看“︁模板:If/doc”︁的源代码
来自康健生活
←
模板:If/doc
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
[[Help:Extension:ParserFunctions|The functions provided by MediaWiki's stock ParserFunctions extension]] with names starting with "#if" [[Manual:Newlines and spaces#Trimming on expansion|trim spaces and newlines]] from the "then" and "else" parts. '''This mediawiki.org template is a wrapper''' easing their use in a way that '''prevents such trimming'''. Spaces still do not affect the outcome of the condition. Parameter 1 selects the if-type as "eq", "expr", "exist" or "error" (for #iferror), or empty "||" for a simple if-there (for #if). The template can be repeatedly nested 6 or 7 levels, one inside the other, because the outer-most is completed before running either the then/else inner levels. This template can be substituted when the expression or comparison will not change. Functionally, a lead-space character is stored, internally, as a simple blank character. Note that in many cases a null nowiki tag ("<nowiki/>") could be used, without [[Template:If]], to allow a lead-space (such as "<nowiki/> xx") anywhere, but the internal storage puts a 43-character marker for "<nowiki/>" in string length. However, there is no extra expansion depth for a nowiki-tag, such as in trailing space, "zz <nowiki/>". ==Usage== '''Where p is implemented in affirmation of the statement and q is implemented in negation of the statement''' *<nowiki>{{if||x| p | q }}</nowiki> gives "{{if||x| p | q }}". Notice the ''pair'' of vertical bars surrounding the empty first parameter. *<nowiki>{{if|expr|2<3| p | q }}</nowiki> gives " p " *<nowiki>{{if|eq| u |u| p | q }}</nowiki> gives "{{if|eq| u |u| p | q }}" *<nowiki>{{if|exist| Help:Link | p | q }}</nowiki> gives "{{if|exist| Help:Link | p | q }}" *<nowiki>{{if|error|{{#expr:x}}| p | q }}</nowiki> gives "{{if|error|{{#expr:x}}| p | q }}" Compare: *<nowiki>{{#if:x| p | q }}</nowiki> gives "{{#if:x| p | q }}" *<nowiki>{{#ifexpr:2<3| p | q }}</nowiki> gives "{{#ifexpr:2<3| p | q }}" *<nowiki>{{#ifeq: u |u| p | q }}</nowiki> gives "{{#ifeq: u |u| p | q }}" *<nowiki>{{#ifexist: Help:Link | p | q }}</nowiki> gives "{{#ifexist: Help:Link | p | q }}" *<nowiki>{{#iferror:{{#expr:x}}| p | q }}</nowiki> gives "{{#iferror:{{#expr:x}}| p | q }}" For example, with a template named ''Template:Template name'' containing the code <nowiki>{{#ifeq: {{{parameter}}} |u| p | q }}</nowiki>, entering the code <nowiki>{{{Template name|parameter=u}}}</nowiki> into an article gives "p", but <nowiki>{{{Template name|parameter=v}}}</nowiki> gives "q". The text of either the then-clause or else-clause is only processed and expanded when triggered. Hence, any templates in use are only expanded once the then-clause or else-clause is matched, otherwise they are skipped as merely paired braces, "{{((}}" with "{{))}}". '''Indentation:''' If indenting the markup, care must be taken to avoid extra newlines when indenting "}}" on the next line. An extra bar pipe "|" can be added after the else-clause to complete that text, and allow "}}" to then be placed anywhere without adding a newline into the else-clause. For example: :::* <nowiki>{{if|{{{1|}}}</nowiki><br> |then found parameter 1|else no parameter 1| ← ''extra'' "|" ''ends else-clause''<br>}} When the else-clause is indented to the next line, a newline (CR/LF) is added: :::* <nowiki>{{if|{{{1|}}}</nowiki><br> |then found parameter 1 ← ''extra newline here''<br> |else noparameter 1|<br>}} To indent the else-clause, split an [[HTML]]-form comment, as "<!--" with next line as "-->|else...". Unless each then-clause and else-clause is carefully tested, to watch for extra newlines, then the results are likely to cause broken lines, with extra line breaks for each newline. For that reason, a global edit with simple search-and-replace of "<code>{#if:</code>" to "<code>{if||</code>" is likely to leave newline problems, wherever the original markup was wrapped to indent either the else-clause or "}}" of each if-structure. Indenting the then-clause is not a problem.
此页面嵌入的页面:
模板:((
(
查看源代码
)
模板:))
(
查看源代码
)
模板:If
(
查看源代码
)
模板:P1
(
查看源代码
)
模板:P2
(
查看源代码
)
返回
模板:If/doc
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。