模板:Exists
||
|{{#ifexist: 模板:Exists/doc
|[編輯]
|[創建]
}}
}} {{#if:|{{{heading}}}|{{#ifeq:模板|模板| 模板文档|文档}}}}|这个說明來自於本頁包含的模板:Exists/doc。(編輯 | 歷史)
}}{{#switch: Exists |sandbox|testcases= |#default= {{#switch: 模板 |模板 |用户= {{#ifexist: 模板:Exists/sandbox |这个模板有沙盒 ([{{fullurl:{{ #rel2abs: /sandbox }}|action=edit}} 編輯]) {{#ifexist: 模板:Exists/testcases |和 測試案例 ([{{fullurl:{{ #rel2abs: /testcases }}|action=edit}} 編輯])}} for editors to experiment. |{{#ifexist: 模板:Exists/testcases |这个模板有測試案例 ([{{fullurl:{{ #rel2abs: /testcases }}|action=edit}} 編輯]) 供编辑者試驗。}} }}}}}}
{{#if:|{{{content}}}|{{#ifexist:模板:Exists/doc | 模板:Documentation subpage This template tests whether a given page exists. It can be useful in view of the maximum number of #ifexist calls that can be used on a page. (However, in the case of frivolous use of #ifexist which was the reason for the limit, do not replace this use with frivolous use of this template!)
The full syntax for using it is:
{{exists | page=page | then=result if page exists | else=result if page does not exist }}
The parameters then
and else
are optional; if not given, the default values for then
and else
are 1 and 0 respectively. The page name may alternatively be given as the first unnamed parameter, as in this short version:
{{exists | page }}
If the page name may contain equals signs, always use the "1=
" or "page=
" prefix.
The method is based on transclusion of the possibly existing page. If the page does not exist the code for page transclusion produces a (red) link. Even if this result is used for comparison only, and not for final output, the page counts as being transcluded. Therefore the page appears as red link in the list of transcluded pages. With #ifexist this can be avoided, and with the CSS method it is not the case.
If the page to be transcluded does not exist, then link brackets are put around the full pagename, with the following conversions (visible with Special:ExpandTemplates):
- a colon is put in front if it is not there yet
- the namespace name (if applicable) and the pagename are capitalized (on most wikis)
- underscores are replaced by spaces
Thus {{help:qq w_x}}
and {{:help:qq w_x}}
both give
[[:Help:Qq w x]]
.
For the link there is not such an automatic conversion. Therefore the template prefixes a colon to the parameter for the full pagename (it should not already start with a colon) and applies lc and anchorencode (to convert spaces to underscores) on both sides before comparison:
{{anchorencode:{{lc:[[:help:qq w_x]]}}}}
gives help:qq_w_x
{{anchorencode:{{lc:{{help:qq w_x}}}}}}
gives 帮助:qq_w_x
Thus a false-positive for a non-existing page is avoided. A false-negative for an existing page is possible, but typically only for specially constructed examples.
See also
}}}}