User:Pathoschild/Help/Template special effects

From Wikipedia, the free encyclopedia

Pathoschilduserspace map ] (Template special effects)


[edit] Check if substituted

{{#ifeq:{{NAMESPACE}}|{{<includeonly>subst:</includeonly>NAMESPACE}}
 |Subst'd
 |Not subst'd
}}

This method uses a logical comparison between the magic namespace word, and the same with a includeonly'd modifier. It is based on the behaviour of the <includeonly> tag: a substituted template will see something like "user|user" (since the <includeonly> tag is applied), while a non-substituted template will see something like "user|{{subst:NAMESPACE}}". If the comparison returns 'not equal', the template is not substituted.

[edit] Produce an error message and hide template

{{#ifeq:{{NAMESPACE}}|{{<includeonly>subst:</includeonly>NAMESPACE}}||{{error:not substituted|AFD}}<div style="display:none;">}}

...template code...

{{#ifeq:{{NAMESPACE}}|{{<includeonly>subst:</includeonly>NAMESPACE}}||</div>}}

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 </div> tag below the template. Otherwise, everything below the check will be hidden.