Help:Advanced templates

From Lunarpedia
Revision as of 09:32, 14 July 2007 by 220.58.64.190
Jump to: navigation, search
Work on this article has outpaced copyediting on it. You can help Lunarpedia by formatting, editing, or tidying it.


Template:H:h This page is an extension of Help:Template. It concerns template names, variable names, and parameters depending on a variable or parameter. Note: This document refers to features currently only available in the Mediawiki software starting with version 1.6 and later.

Some described applications of these techniques may be outdated; for example, if-statements in the extension Parser function are often more convenient. For syntax often used within templates, see ParserFunctions and other "Advanced functioning" help pages listed below. Note that Parser function and ParserFunctions are two different pages.

A template name or a parameter value depending on a parameter or variable

A template name and a parameter value can both depend on a parameter or variable:

This allows branching depending on variables and parameters. However, using parser functions is more versatile.

Since with the method of this section no conditions such as {{{1}}}<a can be evaluated, and no substrings can be extracted from strings (not even currently with parser functions), etc., this works best if each parameter and variable has only a limited number of possible values. For example {{CURRENTDAYNAME}} has only seven possible values, so all cases can be handled with seven templates; if there are really only two cases, five of the seven could be redirects. On the other hand , {{CURRENTTIME}} has 1440 possible values, so it would be impractical to create a template or even just a redirect for each. Even with parser functions all the 1440 values have to be listed, see Template:Tim and Template:Tim. An older method described below is another possibility, see e.g. Template:Tim.

Having multiple parameters, which each can have only few values, is more flexible than having the same total number of possibilities in a single parameter.

If a template depends on PAGENAME, then the many possible values need not be a problem: only the pagenames of the pages that call the template apply, and these can be limited.

Branching according to {{{1}}}=a or {{{1}}}