FANDOM


[edit] [purge] Template-info Template documentation

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).

{{Person
| name      = Arilyn Moonblade
| class3e   = {{class table|edition=3e|sortkey=Moonblade, Arilyn|[[Fighter]]|4|[[Harper agent]]|5|[[Rogue]]|1}}
| alignment = ...
}}

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.

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 {{PAGENAME}}, 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.

Notes

  • Up to ten class/level pairs may be specified.
  • Classes are typically linked to their description pages, but this is not required.
  • It is important that you use the class name as you want it to appear in the categories (i.e., do not use [[Cleric|Priest]], just use [[Cleric]].
  • You may put <ref> tags (or anything else that starts with "<") after either a class or a level. The template should ignore it. However, this will cause misalignment of the columns in the table. Note the {{Person}} template allows citations to be put in the subtitles of edition-specific sections, and this is recommended for the best looking class table.
  • The sortkey only applies to the dynamic categories generated by this template. If you specify a sortkey, then you should also add a {{DEFAULTSORT:}} to your page so any static categories will also place your page in the correct alphabetical order.

Under the Hood

This template is fairly straightforward because most of the brains are in the helper templates:

{{Nth}} 
Converts a number to its counting or ranking form. {{nth|3}} returns 3rd.
{{Class plural}} 
Returns the plural form of a class title. {{class plural|Thief}} returns Thieves. 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 "<" symbol, if any. This will remove any <ref> tags or other HTML markup that might be appended to a string (the level, in this template).
{{Unlink}} 
Returns the string between square brackets. {{unlink|[[Fighter]]}} returns Fighter. 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. {{Rootlink|[[Beguiler (class)|Beguiler]]}} returns [[Beguiler (class).

Here is the part of the template that operates on the first class/level pair:

{{#if:{{{1|}}}{{{2|}}}|
[[Category:{{ucfirst:{{class plural|{{unlink|{{rootlink|{{stripref|{{{1}}} }} }} }} }} }} of {{nth|{{stripref|{{{2}}} }} }} level ({{{edition}}}){{#if:{{{sortkey|}}}|{{!}}{{{sortkey}}}}}]]
[[Category:{{ucfirst:{{class plural|{{unlink|{{rootlink|{{stripref|{{{1}}} }} }} }} }} }} ({{{edition}}}){{#if:{{{sortkey|}}}|{{!}}{{{sortkey}}}}}]]
}}

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:

{{class table|edition=3e|sortkey=Baenre, Jarlaxle|[[thief]]<ref name="foo" />|4}}

The value of {{{1}}} will be the class and the ref tag, [[thief]]<ref name="foo" />, the value of {{{2}}} will be the level, 4, the value of {{{edition}}} will be 3e, and the value of {{{sortkey}}} will be Baenre, Jarlaxle. Breaking down the first category line, just look at this part:

[[Category:{{ucfirst:{{class plural|{{unlink|{{rootlink|{{stripref|{{{1}}} }} }} }} }} }}

[[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 "<" character and removes it and anything following it, returning [[thief]]. {{rootlink}} extracts all characters up to the first pipe symbol (|), but since there isn't one it just returns [[thief]] unchanged. Then {{unlink}} changes [[thief]] to thief. Then {{class plural}} changes thief to thieves. And finally, {{ucfirst:}} capitalizes the first letter and returns Thieves. So far, we have generated this:

[[Category:Thieves

Now look at the second half of the line:

of {{nth|{{stripref|{{{2}}} }} }} level ({{{edition}}}){{#if:{{{sortkey|}}}|{{!}}{{{sortkey}}}}}]]

The word of is appended, and then we see {{nth|{{stripref|{{{2}}} }} }}. The value of {{{2}}} is 4 so {{stripref}} just returns 4. Next the {{nth}} template changes the 4 to 4th. At this point we have assembled this string:

[[Category:Thieves of 4th

The word level is appended, and then ({{{edition}}}) 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:{{{sortkey|}}}|{{!}}{{{sortkey}}}}}]]

If {{{sortkey|}}} 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

[[Category:Thieves of 4th level (3e)|Baenre, Jarlaxle]]

The other category is even simpler.

The ten repetitions of this code block are surrounded by an if statement that checks to see if edition has a value and skips the whole category thing if not. Similarly, one more if 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.

References


Community content is available under CC-BY-SA unless otherwise noted.