Template:Exists/doc: Difference between revisions

From VNDev Wiki
Created page with "{{Documentation subpage}} This template tests whether a given page exists. This is meant to replace the #ifexist parser function which creates unnecessary links in Special:WantedPages in a page does not exist. ==Usage== The full syntax for using it is: {{tlx|exists|page}} {{tlx|exists|page=''page''|then=''result if page exists''|else=''result if page does not exist''}} The parameters <code>then</code> and <code>else</code> are optional; if not given, the default..."
 
No edit summary
 
Line 1: Line 1:
{{Documentation subpage}}
{{Documentation subpage}}


This template tests whether a given page exists. This is meant to replace the #ifexist parser function which creates unnecessary links in [[Special:WantedPages]] in a page does not exist.
This template tests whether a given page exists. This is meant to replace the #ifexist parser function which creates unnecessary links in [[Special:WantedPages]] in a page does not exist.  This has the advantage of avoiding spurious wikilinks, but has the disadvantage that the containing page may not be updated automatically if the checked page is created or deleted later.  


==Usage==
==Usage==
Line 7: Line 7:


{{tlx|exists|page}}
{{tlx|exists|page}}
{{tlx|exists|page=''page''|then=''result if page exists''|else=''result if page does not exist''}}


The parameters <code>then</code> and <code>else</code> are optional; if not given, the default values for <code>then</code> and <code>else</code> are ''1'' and ''0'' respectively.
{{tlx|exists|page{{=}}''page''|then{{=}}''result if page exists''|else{{=}}''result if page does not exist''}}


==Explanation==
The parameters <code>then</code> and <code>else</code> are optional; if not given, the default values for <code>then</code> and <code>else</code> are ''true'' and ''<blank>'' respectively.
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.
 
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 <code><nowiki>{{help:qq w_x}}</nowiki></code> and <code><nowiki>{{:help:qq w_x}}</nowiki></code> both give <code><nowiki>[[:Help:Qq w x]]</nowiki></code>.
 
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:
 
*<code><nowiki>{{anchorencode:{{lc:[[:help:qq w_x]]}}}}</nowiki></code> gives {{anchorencode:{{lc:[[:help:qq w_x]]}}}}
*<code><nowiki>{{anchorencode:{{lc:{{help:qq w_x}}}}}}</nowiki></code> gives {{anchorencode:{{lc:{{help: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.

Latest revision as of 20:13, 18 June 2022

This template tests whether a given page exists. This is meant to replace the #ifexist parser function which creates unnecessary links in Special:WantedPages in a page does not exist. This has the advantage of avoiding spurious wikilinks, but has the disadvantage that the containing page may not be updated automatically if the checked page is created or deleted later.

Usage

The full syntax for using it is:

{{exists|page}}

{{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 true and <blank> respectively.