Template:Class table/doc

Description
This template used to be a simple redirect to the split table template. It has been modified to automatically generate categories for each class/level combination listed in the table. It is intended to be used in the Person template and any other template the describes a creature that has a "class" and a "level". The generation of categories is optional and will only occur if the edition parameter is set.

Example
This is an example of the template being used inside the Person template (most parts of template not shown).

This example will place the page in the following categories: The sortkey will ensure that in each of these categories the page is filed under "M" for Moonblade rather than "A" for Arilyn.
 * Category:Fighters (3e)
 * Category:Fighters of 4th level (3e)
 * Category:Harper agents (3e)
 * Category:Harper agents of 5th level (3e)
 * Category:Rogues (3e)
 * Category:Rogues of 1st level (3e)

Usage

 * edition : Optional. If this is set, categories will be generated for each class/level pair listed thereafter. Each category will be appended with this value, in parentheses. Values should be: 1e, 2e, 3e, 4e, 5e and so on. By convention, 3.5 edition is considered 3e because the classes did not change significantly between 3rd edition and 3.5, but 3.5 (or whatever you decide) can be used if desired.
 * sortkey : Optional. If categories are being generated, then the sortkey will determine where in the alphabetical list of pages your page will appear. The default is to sort by the, but you can change it with this parameter.
 * (class names) : The first value in a class/level pair, this will usually be a link to the article describing the class, but it's not required to be a link.
 * (levels) : The second value in a class/level pair, this must be a number with no suffix (i.e., use 4 not 4th).
 * nocat : Setting this to true will suppress the generation of categories. This is primarily used on documentation pages like this one so it doesn't show up in the categories.

Under the Hood
This template is fairly straightforward because most of the brains are in the helper templates: Here is the part of the template that operates on the first class/level pair:
 * Nth : Converts a number to its counting or ranking form.  returns .
 * Class plural : Returns the plural form of a class title.  returns . Case is preserved, but the category will use the capitalized version. If new classes are added, and the plural form is something other than adding an "s" suffix, please add them to Class plural.
 * Stripref : Returns everything up to, but not including, the first "&lt;" symbol, if any. This will remove any &lt;ref&gt; tags or other HTML markup that might be appended to a string (the level, in this template).
 * Unlink : Returns the string between square brackets.  returns . It shouldn't matter how many brackets are present, including zero.
 * Rootlink : Returns everything up to but not including the first pipe symbol . This removes any alt-text of a link.   returns .

The template is essentially ten repeats of this code block. In English, if the first or second parameter have a value then the next two lines will generate categories (so be sure to specify both a class and a level or the results won't be pretty). Starting with this invocation of the template:

The value of  will be the class and the ref tag, , the value of   will be the level,  , the value of   will be  , and the value of   will be. Breaking down the first category line, just look at this part: [[Category: starts the category tag and then we hit the first set of double braces,  . These form a pair with the last set, , at the end of the line. Working from the inside out, stripref looks for a "&lt;" character and removes it and anything following it, returning  . rootlink extracts all characters up to the first pipe symbol  , but since there isn't one it just returns   unchanged. Then unlink changes   to  . Then class plural changes   to  . And finally,  capitalizes the first letter and returns  . So far, we have generated this: [[Category:Thieves Now look at the second half of the line: of  level ]] The word   is appended, and then we see  . The value of   is   so stripref just returns  . Next the nth template changes the   to  . At this point we have assembled this string: [[Category:Thieves of 4th The word   is appended, and then   appends the value of edition, inside parentheses, to the end. Now we have this: [[Category:Thieves of 4th level (3e) Finally we come to the sortkey: ]] If   has a value, then we append a vertical bar (  evaluates to the "|" symbol. This is necessary because if we just typed the bar in, the #if: would think we were specifying an else clause.) and the value of sortkey. Finally, the category link is closed with  , resulting in

The other category is even simpler.

The ten repetitions of this code block are surrounded by an  statement that checks to see if edition has a value and skips the whole category thing if not. Similarly, one more  statement surrounds everything and will skip the categories if the parameter nocat is set to true.

So why does the source code look like a bunch of wavy lines with a few words sprinkled about? Well, the extra whitespace that it takes to make the code almost readable will be part of the return value of the template, and that puts blank lines at the end of the table, at least one for each unused row. Therefore, all of the newline/carriage returns in the code had to be removed, making the template one really long line of wikitext. Sorry.