Extension:ExpandTemplates

Special:ExpandTemplates provides an input box to enter wikitext, and another one to enter a pagename, and produces expanded wikitext, i.e., templates, parser functions and variables are expanded recursively; variables depending on pagename are expanded based on the supplied pagename. It also shows how the produced wikitext is rendered. This is typically the same as how the original wikitext is rendered, but not always.

In special cases the expanded wikitext changes when expanded again: this may apply e.g. if a template is expanded containing "|" or braces: in this case these characters are treated as plain text in the expansion as applied by ExpandTemplates, and, accordingly, in page rendering. This is used in, which provides a way to allow "|" in a parameter value of a template or parser function, in particular for use in table syntax. This template can be used with ExpandTemplates to perform partial substitution.

The table, using, allows comparison of the wikitext produced with simple substitution and with ExpandTemplates (recursive substitution). It also shows that "subst" prevents ExpandTemplates from expanding the template. It also demonstrates, using also }, that a template call with a parameter separator "|" in the form | prevents ExpandTemplates from expanding the template.

Remove comments
The "Remove comments" option selects whether comments are removed, not just in the final result but throughout the expansion process. This affects the result of parser functions: a comment in the expression of #expr or #ifexpr gives an error message unless "Remove comments" is on, and comments affect #if and ifeq.

Example:

Normal expansion, and ExpandTemplates with "Remove comments" on:

Full substitution, and ExpandTemplates with "Remove comments" off:

Expression error: Unexpected &lt; operator

0

1

XML parse tree
Optionally the XML parse tree is shown. For example:

a b|c

2024

gives

a b|c

 CURRENTYEAR

  a

 #ifeq:2   3     a     b

 #switch:a  a = 3    b = 4    a = 5

 a   b    c = de|fg     h

 a   b

Thus:
 * The result shows a stage in processing before actual evaluation. Thus even names of variables, parser functions, and templates have not been determined. Also, the colon and "#" are not detected yet, so no distinction is made between variables, parser functions, and templates, let alone that there would be distinction between existing and non-existing variables, parser functions, and templates.
 * A pair of double rectangular brackets shields "|" from being interpreted as a parameter separator, but links are not shown separately in the tree.
 * In the case of a double definition of a parameter value, the discarding of the first is not yet in the result.

Input text in URL
The wikitext serving as input can also be put in the URL, e.g., using urlencode: giving.

" | ", using, prevents the template texpr from expanding in the URL, and also prevents "|" from being interpreted as a separator of the parameter of urlencode from a dummy second parameter. It can also be used in a template call without parameters, albeit that in the input box of ExpandTemplates this becomes a template with unnamed parameter being the empty string instead of undefined; e.g. . This does not work for variables and parser functions, use percent codes for one pair of braces instead (see wikitext); for the ParserFunctions prefix "#" use %23:

.

.

Installation

 * 1) Download the latest snapshot and extract it to your extensions directory.
 * 2) Add the following at the end of your LocalSettings.php:

Adjusting the box width
By default the width of the input and result box is only 11 characters. You may want to change this to full width by adding something like the following to your CSS: