User:Pathoschild/Help/Template special effects

Substitution check
There are two methods to detect substitution, both depending on the MediaWiki parser's order of operations. They are essentially the same technique, but modified to best achieve one of two goals:
 * A clean output like " This template must be substituted ", but with code left over on the page after substitution.
 * Remove the check code when substituted, but corrupt output like " This template must be substituted ".

There's no known way to achieve both clean visible output and code removal.

Not substituted (clean visible output, but code left behind)
This method uses a logical comparison between the magic namespace word, and the same with a includeonly'd modifier. When substituted, the check will compare something like "user|user" (since the tag is applied), while a non-substituted check will compare something like "user| ". If the comparison returns 'not equal', the template is not substituted.

However, the code will remain on the page when the page is substituted.

Substituted (corrupt output, but no code left behind)
Subst'd

This method exploits related behaviour: when substituted, the ParserFunction does not recognize empty default parameter values (ie, it will see " " when substituted rather than the usual ""). If it is not substituted, the check fails (because the condition becomes blank) and we know it's not being substituted.

Example
The following code in a template will replace the normal template output (when it is not substituted) with an error message. 

...template code...

The CSS style will hide the box if it is not substituted, since many users may not notice the little error message above it (or not care). That aspect can easily be removed if desired. If the CSS class is used, add a closing  tag below the template. Otherwise, everything below the check will be hidden.