Columns

Summary: Create columns out of lists without using table markup
Version: 1.1 - 2006-06-06
Maintainer: MartinFick
Discussion: Columns-Talk
Category: Layout

Question

How can I display lists in columns without adding all that table markup code or being preoccupied with the number of columns up front?

Answer

Put columns.phpΔ in your cookbook/directory.

Add the following line to local/config.php

    @include_once("$FarmD/cookbook/columns.php");

This recipe defines a (:columns # Page:) directive, which acts a lot like an (:include:) directive. This directive formats the included text so that the items in the source list will be placed into a table, with the number of columns that you specify. Placement of the (originally vertical) list items proceeds left to right and top to bottom, as illustrated in the following mock-up:

Source, located at SourcePageName

item1
item2
item3
item4
item5
item6
item7

Output Example 1, using (:columns 2 SourcePageName:)

item1 item2
item3 item4
item5 item6
item7

Output Example 2, using (:columns 3 SourcePageName:)

item1 item2 item3
item4 item5 item6
item7

Syntax: (:columns # SourcePageName:)

The number of columns per row must be specified before the SourcePageName.

This recipe will put columns into a table for you, rather than a <div> arrangement, and is useful for long lists which simply need to be put into a table with multiple columns to save vertical space. This allows authors to focus on creating the list without giving thought to how to split up the list into columns. The number of columns is easy to change at any time without having to edit the source list.

Notes and Comments

The output uses bare <TABLE>, <TR>, and <TD> tags. It could really use some better CSS integration, but I don't know how.

Possible Enhancements:

  • Put the contents of each <td> section on a line of its own so that !! Headers will be recognized.
  • Add flow=vertical/horizontal switches to make columns flow vertically instead of horizontally.
  • Add basic template support (like pagelist templates). Templates would use {=$Row} and {=$Cell} variables?
  • Of course, templating this recipe just leads to the idea of a generic data templating system. If there were such a system, this recipe would only need to be used to groups things into generic row/fields which could then be formatted by the data templating system.

Versions

  • This recipe was last tested on PmWiki version: 2.1.6

2006-06-06 : Columns - version 1.1 - Martin Fick

  • Fixed minor bug so that directive does not need a return
  • Fixed minor bug where any page named Include would get included instead

2006-06-02 : Columns - version 1 - Martin Fick

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

Martin Fick

Comments

See discussion at Columns-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.