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. In either case, this template passes its parameters to split table for rendering the actual table.

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:
 * Category:Fighters (3e)
 * Category:Fighters of 4th level (3e)
 * Category:Rogues (3e)
 * Category:Rogues of 1st level (3e)
 * Category:Harper agents (3e)
 * Category:Harper agents of 5th level (3e)

Usage

 * edition : Optional. If this is set, categories will be generated for each class/level pair listed after. 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. If unset, behavior defaults to split table.
 * (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 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.

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,  , 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  . Then unlink changes   to  . Then class plural changes   to  . And finally, ucfirst: 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 finally,   appends the value of edition, inside parentheses, to the end and then 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.