User:Wlgrin/Sandbox/Generic/Main/Template001/doc

The At User template is a shortcut used to help transclude user pages (typically, user templates) within other user pages belonging to the same user. As a safeguard, the behaviour of depends on whether the transcluding page is itself within user space (as expected) or not, thereby avoiding the inadvertent transclusion of pages from user space into Wikipedia articles or project pages.

Basic usage
Template takes a single, unnamed parameter   : the name of a user page to transclude.

Using, one may replace calls such as

with the relatively simpler form

Since only expands the name of the transcluded page, the whole call (and any parameter list that may follow) must be nested within another pair of double braces.

If the transcluding page is in user space (i.e., in the     or      namespace), the template called through  will be found in a sub-page of “    :user-name/    /” (where user-name is derived from the name of the transcluding page). If the transcluding page is in any other namespace, the template is found normally (by default, in namespace    ).


 * {| class="wikitable collapsible collapsed" style="min-width:30em;"

!style="text-align:left;"|Examples
 * style="padding:1em;"| For example, if the transcluding page is “   :MeMyselfEtMoi/My current projects”, using
 * style="padding:1em;"| For example, if the transcluding page is “   :MeMyselfEtMoi/My current projects”, using

will produce (during parsing)
 * 

This expanded call will then be parsed to produce, on the page displayed, the result of transcluding. If the same call was inadvertently copied into an article (outside user space), it would instead expand to
 * 

with the effect of transcluding.
 * }

Prefixing with “/”
If the name of the transcluded page (passed as first parameter to ) begins with a “/” and the transcluding page is in user space, the template is searched in a sub-page of “   :user-name” (instead of “    :user-name/    /”). If the transcluding page is not in user space, only the terminal sub-page name is kept (i.e., the leading “/” and any parent sub-page names are dropped).


 * {| class="wikitable collapsible collapsed" style="min-width:30em;"

!style="text-align:left;"|Examples
 * style="padding:1em;"| For example,
 * style="padding:1em;"| For example,

will produce
 * 

If this same call was inadvertently copied into an article (outside user space), the leading “/” and parent sub-page name “Sandbox” would be stripped and the call would expand to
 * 


 * }

Using substitution
can be safely substituted, since it uses the “safesubst” modifier to call parser functions and magic words and it does not transclude any other page.

Rather than being just a typing aid, aims at reducing the visual clutter caused by a large number of transclusions of user templates in a user page. For that reason, it is generally best to transclude it and not substitute it. However, it is useful to substitute in two cases:
 * when substituting the page whose name is passed as parameter to, and
 * when eliminating from a page (for example, while moving the transcluding page from a user sandbox to main article space).

If you want to substitute the page whose name is passed as parameter to, you must also substitute template itself. This is because the MediaWiki parser performs all substitutions before performing any transclusion. The resulting notation is verbose and such use of has little appeal.


 * {| class="wikitable collapsible collapsed" style="min-width:30em;"

!style="text-align:left;"|Examples
 * style="padding:1em;"| For example, this incorrect call :
 * style="padding:1em;"| For example, this incorrect call :

will produce the likely unintended reproduction, on the displayed page, of the code calling “My template” (instead of displaying the result of its actual transclusion or substitution):
 * <samp style="padding-left:1em; padding-right:1em; background-color:#FFF2E6;">

By contrast,

will produce, as expected, the substituted output of <tt> </tt>. On the other hand, you can safely substitute without substituting the transcluded page:


 * }

Caveats
If you do not need to pass any parameter, remember to separate the two closing sets of double braces; otherwise, the closing series of four braces will confuse the MediaWiki parser. For example, you can use as separator a space or a pipe. Using a pipe will cause an empty unnamed parameter to be passed to the transcluded page, which is generally without adverse consequences (but check the syntax of the transcluded page to confirm that assumption).


 * {| class="wikitable collapsible collapsed" style="min-width:30em;"

!style="text-align:left;"|Examples
 * style="padding:1em;"| For example, this incorrect call :
 * style="padding:1em;"| For example, this incorrect call :

will produce the likely unintended output
 * <samp style="padding-left:1em; padding-right:1em; background-color:#FFF2E6;"> {My template}

By contrast,

will produce, as expected,
 * <samp style="padding-left:1em; padding-right:1em; background-color:#F2FFE6;">

Similarly, using a pipe,

will produce
 * <samp style="padding-left:1em; padding-right:1em; background-color:#F2FFE6;">


 * }

Automated processing
Since there are no valid reasons for this template to appear outside user space, an automatic script (bot) could be written to detect and strip it from non-user pages. Using substitution is the best option to do this. Otherwise, the call itself may be munged, leaving only the name of the transcluded page in its place (<tt> </tt> becoming <tt> Abc </tt>) and, if there is a leading “/”, taking care of stripping it as well as the names of any parent sub-pages (<tt>  </tt> also becoming <tt> Abc </tt>).