CreateColumns

Summary: quickly divides up a list of items into separate columns within a table
Version: 2010-12-16
Prerequisites: none
Status:
Maintainer: overtones99
Discussion: CreateColumns-Talk
Users: (View / Edit)
Categories: Markup Tables

Questions answered by this recipe

  • is it possible to automatically divide up a list of items into separate table columns?

Description

CreateColumns quickly divides up a list of items into separate columns within a table and outputs the necessary PmWiki (:table:) and (:cell:) TableDirectives markup. A user can a) easily distribute a list of items over a specific number of columns, or b) specify the number of items you'd like to list per column so that new columns are automatically added when additions to the list are made.

Notes

To install, add createColumns.phpΔ to your Cookbook, and add to your config.php:

include_once('cookbook/createColumns.php');

Usage & Basic Format

The following markup creates a table with 3 items per column, in this case resulting in 2 columns...

   (:createColumns perColumn=3 tableOptions="width=90% align=center" cellOptions="align=center":)
   item 1
   item 2
   item 3
   item 4
   item 5
   (:createColumnsend:)

... which basically just outputs the following PmWiki table markup:

   (:table width=90% align=center:)
   (:cellnr cellOptions="align=center":)
   item 1
   item 2
   item 3
   (:cell cellOptions="align=center":)
   item 4
   item 5
   (:tableend:)

Adding more items to the list would eventually lead to the automatic addition of more columns.

Additionally, you can instead specify a finite number of columns, and CreateColumns will divide up the list evenly. For example:

   (:createColumns nColumns=3 tableOptions="width=90% align=center" cellOptions="align=center":)
   item 1
   item 2
   item 3
   item 4
   item 5
   (:createColumnsend:)

... which results in:

   (:table width=90% align=center:)
   (:cellnr cellOptions="align=center":)
   item 1
   item 2
   (:cell cellOptions="align=center":)
   item 3
   item 4
   (:cell cellOptions="align=center":)
   item 5
   (:tableend:)

Arguments

  • perColumn - if used (instead of nColumns), this will determine the max number of items to place in each column; additional columns will be created until all listed items have been placed
  • nColumns - if used (instead of perColumn), this will try to evenly distribute items between a specified number of columns -- using nColumns will override perColumn
  • tableOptions="..." - inserts options into (:table ... :)
  • cellOptions="..." - inserts options into (:cell ... :) and (:cellnr ...:)
  • tableMarkup - setting tableMarkup=0 will supress the output of (:table ... :) and (:tableend:), which is useful if you want to create a list of columns within a pre-existing table

Inserting a List into a Pre-Existing Table via tableMarkup=0

It's also possible to insert CreateColumns into a pre-existing table by specifying tableMarkup=0. This will supress the output of (:table ... :) and (:tableend:) markup, but will continue to insert (:cell:) and (:cellnr:) markup into the list. For example:

   (:table width=90% border=1:)
   (:cellnr:)yeah yeah yeah
   (:cell:)uh huh
   (:createColumns nColumns=3 tableMarkup=0 cellOptions="align=center":)
   item 1
   item 2
   item 3
   item 4
   item 5
   (:createColumnsend:)
   (:tableend:)

... will result in:

   (:table width=90% border=1:)
   (:cellnr:)yeah yeah yeah
   (:cell:)uh huh
   (:cellnr cellOptions="align=center":)
   item 1
   item 2
   (:cell cellOptions="align=center":)
   item 3
   item 4
   (:cell cellOptions="align=center":)
   item 5
   (:tableend:)

Release notes

  • fix "preg_replace(): The /e ..." and other errors Wlkl
  • 2010-12-16 - initial release

See also

  • Columns   Create columns out of lists without using table markup
  • CreateColumns   quickly divides up a list of items into separate columns within a table
  • MakeColumns   Create columns on a page without using tables.
  • MakeManyColumns   How to make columns on a page using CSS
  • MultiColumn   Allow text to flow into multiple columns

Contributors

overtones99

Comments

See discussion at CreateColumns-Talk

User notes : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.