Template talk:Columns

From NeoDex
Jump to: navigation, search


Does this sound familiar to you?

Two items from the second to the first column, and one from the second to the third - no, wait! One from the third to the second! No, but I already moved one the other way - TWO from the third to the second... Argh!

Actual dialogue from every time TNT release a new colour, there. BUT NO LONGER! Thanks to the Macbeth Columnomatic 3000TM, multiple columns is a breeze!

Simply call up the columns template like so:


and enter in your entire list in one go, no cells required!


*[[Acara]] - ''June 28, 2013''

*[[Aisha]] - ''January 4, 2012''

*[[Blumaroo]] - ''August 8, 2013''

*[[Bori]] - ''October 15, 2014''

*[[Chomby]] - ''March 22, 2012''

[... and so on...]

*[[Wocky]] - ''December 12, 2012''

*[[Xweetok]] - ''April 7, 2012''

*[[Yurble]] - ''March 1, 2014''

*[[Zafara]] - ''February 2, 2013''


The Macbeth Columnomatic 3000TM uses an exclusive, clinically studied anti-headache ingredient to automatically create and level off the columns for you. The Columnomatic 3000TM will also centre the columns on the page for you, FREE OF CHARGE. You can over-ride this and set your own table options with the options parameter, like this:



Using the patent-pending Delightful Index CategorisaTION Auto-Repopulation Yardstick (DICTIONARY), the Columnomatic 3000TM will automatically sort your list into alphabetical order! That's right, you don't even need to think about the list any more! Put the new entries at the end! At the beginning! Anywhere you like, the Columnomatic won't mind. (You can override this with the sort parameter. Set to none to return the lists in the order you entered them, reverse for the opposite order the list was entered in, desc for reverse alphabetic order, or random.)

We guarantee* that it will change how you edit the Neodex... forever. ORDER TODAY!

*not actually guaranteed. Your statutory rights are not affected.

--Macbeth (talk) 22:32, 22 October 2014 (UTC)

Technical stuff[edit]

This template works by taking the list you give it (parameter 1) and converting it into an array using the asterisk character, *, as a delimiter. This is already used in all the three column lists across the Neodex as it is wikicode for a(n unordered) list item. I first started by using the new line character to delimit array items (in case I or anyone else needs to do it again, a hard return won't work, use a regex, i.e. /\n/), however, I guess because of the order in which the wikicode processing is run, the asterisks were printed just as asterisks, and didn't work as the magic word for a list item.

Using the asterisk as the delimiter instead strips the (useless) asterisk from the list items, and I am able to make them render as list items by using the html </li><li> as the delimiter when the array is printed. As the first list item has an asterisk at the beginning, this creates an empty array item (array[0] = ""; array[1] = "first bullet point"). The arrayunique function automatically removes the empty entry at the beginning (and any other empty entries). NB: it will also remove duplicate list items - knowing what this will be used for at this time, I think that's a good thing, but if this template is used for some other purpose, bear this in mind.

The array containing the entire list is used to make three new arrays. The first one contains everything up to a third of the way through the list. This becomes the first column. The rest of the list is divided equally into two lists: if the rest of the list has an odd number of entries, the second column will get (should get) the extra one. Hence, the columns level themselves.

Oh, and this is all possible thanks to the Arrays extension that Blue installed very kindly at my request. (Another) Big round of applause for Blue!

My pleasure. I look forward to seeing the Columnomatic 3000TM in action. Great work, Macbeth! ~ Blue (talk) 23:43, 22 October 2014 (UTC)

Short columns[edit]

A basic bit of error handling is included in that the template will check that the list it is about to print isn't empty before it prints. This should mean that very short lists won't generate empty columns. A list of two entries should be handled like this: the first column takes the first 2/3 rounded up = 1 entry. The second column takes the remaining list, 2 entries - 1 entry in the first column = 1 entry, and takes 1/2 rounded to the nearest integer = 1 of them. This array is not empty, and so the template prints the second column. The third array takes the rest of the list, but there are no items left. The template realises it is an empty array, and doesn't make a third column at all.

--Macbeth (talk) 22:48, 22 October 2014 (UTC)