Translations of this page?:

columns plugin

columns plugin by Michael Arlt
Arrange information in multiple columns

Last updated on 2008-10-08. Provides Syntax.
Compatible with DokuWiki 2008-05-05.

Tagged with columns.

Description

You can arrange your information in multiple columns. Column breaks must be inserted manually. I use a table with one <td> for each column. This worked best together with the S5 plugin from Andreas Gohr.

Syntax

Simply add two lines around your information and enter your column breaks.

The first parameter is the width of the table. The following parameters are for the columns. If you do not want to specify a value for the table- or column-width use ”-” instead.

<columns>

information in column 1

~~NEWCOL~~

information in column 2

</columns>
<columns 100% 50% - ->

information in column 1 (50% width)

~~NEWCOL~~

information in column 2

~~NEWCOL~~

information in column 3

</columns>

Columns2 Branch

The syntax is mostly identical to the original version, except that the new column keyword has to be specified within angle brackets1):

<columns 100% 50% - ->

information in column 1 (50% width)

<newcolumn>

information in column 2

<newcolumn>

information in column 3

</columns>

By default the text in columns is justified. This can be changed by adding asterisks on either side of the column width specification. The asterisk indicates non-justified side of the text block, so to achieve left alignment add the asterisk on the right side.

<columns 100% 25% 25%* *-* *->

Justified text

<newcolumn>

Aligned on the left side

<newcolumn>

Center-aligned

<newcolumn>

Aligned on the right side

</columns>

Localisation

The keywords can be customized - see Dokuwiki: administration → configuration.

Language Start End Next Column
English <columns> </columns> ~~NEWCOL~~
German <spalten> </spalten> ~~NEUESPALTE~~
Spanish <columnas> </columnas> ~~NUEVACOLUMNA~~
$lang['kwcolumns']
$lang['kwnewcol']

Download / Installation

Install the current release with the plugin manager. Have a look at the DokuWiki plugin configuration.

2008-10-08 Download Columns2 branch
2008-09-29 Download Columns2 branch
2007-10-22 Download Latest version of the original plugin by Michael Arlt

Source Code

syntax.php

<?php
/**
 * columns Plugin: Arrange information in mulitple columns
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Michael Arlt <michael.arlt [at] sk-schwanstetten [dot] de>
 * @version    2007-10-22
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
function td($tdwidth,$css)
{
  if ($tdwidth == "-")
  {
    return '<td style="'.$css.'">';
  }
  else
  {
    return '<td style="width:'.$tdwidth.';'.$css.'">';
  }
}
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_columns extends DokuWiki_Syntax_Plugin {
 
    /**
     * function constructor
     */
    function syntax_plugin_columns(){
      // enable direct access to language strings
      $this->setupLocale();
    }
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Michael Arlt',
            'email'  => 'michael.arlt@sk-schwanstetten.de',
            'date'   => '2007-10-22',
            'name'   => 'columns Plugin',
            'desc'   => 'Arrange information in multiple columns',
            'url'    => 'http://www.dokuwiki.org/plugin:columns',
        );
    }
 
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'formatting';
    }
 
function getPType(){
        return 'normal';
    }
 
    /**
     * What modes are allowed within our mode?
     */
    function getAllowedTypes() {
        return array('substition','protected','disabled','formatting');
    }
 
    /**
     * Where to sort in?
     */
    function getSort(){
        return 1;
    }
 
    function connectTo($mode) {
      $kwcolumns=$this->getConf('kwcolumns');
      if ($kwcolumns=="") { $kwcolumns=$this->lang["kwcolumns"]; };
      $this->Lexer->addSpecialPattern('<'.$kwcolumns.'.*?>.*?</'.$kwcolumns.'>',$mode,'plugin_columns');
    }
 
    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler)
    {
      $kwnewcol=$this->getConf('kwnewcol');
      if ($kwnewcol=="") { $kwnewcol=$this->lang["kwnewcol"]; };
      $kwcolumns=$this->getConf('kwcolumns');
      if ($kwcolumns=="") { $kwcolumns=$this->lang["kwcolumns"]; };
 
      $length=strlen($this->lang["kwcolumns"])+2;
      $end=strpos($match,">");
      if($end > $length)
      {
        $width=preg_split('/ /',substr($match,$length,$end-$length));
      }
      #$lines="$kwcolumns:$kwnewcol:".substr($match,$length,$end-$length).":";
      $css1=$this->getConf('css1');
      $css2=$this->getConf('css2');
      $css3=$this->getConf('css3');
      $lines.='<table';
      if ($width[0] != "-")
      {
        $lines.=' style="width:'.$width[0].'"';
      }
      $lines.= '><tr>';
      $column=0;
      foreach (preg_split('/'.$kwnewcol.'/',substr($match,$end+1,-$length-1)) as $col)
      {
        if ($column==1) # first column
        {
          $lines.=td($width[$column],$css1);
          $lines.= p_render('xhtml',p_get_instructions($oldcol),$info);
        }
        else
        {
          if ($column>1) # all other columns
          {
            $lines.=td($width[$column],$css2);
            $lines.= p_render('xhtml',p_get_instructions($oldcol),$info);
          }
        }
        $column++;
        $oldcol=$col;
      }
      $lines.=td($width[$column],$css3);
      $lines.= p_render('xhtml',p_get_instructions($oldcol),$info); # last column
      $lines.='</td></tr></table>';
      return $lines;
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml'){
          $renderer->doc .= $data;
          return true;
        }
        return false;
    }
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :

Change History

Columns2 Branch

2008-10-08

  • Added nesting support
  • Removed extra margin at the bottom of the columns block, which together with paragraph margin of the column content often caused double margin

2008-09-29

  • Added Spanish localization (thanks to Digna González Otero)
  • Added Russian localization

2008-09-14

  • Added extended syntax to specify text alignment in the columns
  • To make the syntax fully compatible with the original plugin, the angle brackets around the new column keyword can be disabled from the configuration manager

2008-08-23

  • Fixed issue with the backlinks
  • Columns styling is moved from configuration to style.css file
  • Slightly different syntax: the new column keyword is wrapped in angle brackets (i.e. <columns> … <newcolumn> … </columns>)

2007-10-22

  • First public release
  • All desired features of the author are implemented

Thanks to ...

Andreas Gohr for Dokuwiki and now: S5!

License

This product is released under the GPL 2

Discussion

BUGs

  • The new release does not process headlines inside columns. e.g. the following code results on the plain ===== Headline =====:
    <columns 100% 50% - > ===== Headline ===== <newcolumn> nonono </columns>

    Rodrigo Rebouças 2008/10/12 16:27


I'm not sure it's a bug per definition. AFAIK, there is no error in the plugin that would cause it. It seems that DokuWiki has a limitation that doesn't allow to include headings into other modes.

While the headings look like a nice feature at the first glance, there are number of questions that arise when you consider it in detail:

  • If there are two columns in a block and the first one uses heading, should the left margin associated with the heading level be applied also to the contents of the second column?
  • If there is a nested columns block in the first column, should the margin be applied to every nested column?
  • What about text after the columns block (out of plugin scope), should the margin be applied there?

While you can come up with some answers to these questions, it seems to be too complicated and against the DokuWiki rules. So for now keep the headings out of columns. — Mykola Ostrovskyy 2008/10/13 8:30


I started using the 2007-10-22 release, now without problems with headings. You can see an example here: http://meninosdarede.org.br/site/ajudeRodrigo Rebouças 2008/10/13 12:54


While you can come up with some answers to these questions…

So your answer is no margin. Works fine with your template but will look not so nice with the default one.

The 2007-10-22 release also has a number of problems and I'm afraid it won't be easy to take best of both. Though, never say never. If more people will ask I might reconsider ;-)Mykola Ostrovskyy 2008/10/13 20:32

Nested Blocks

Nice plugin but could be awesome if you could use it in nested blocks. Thanks for your work :D.

Angelo Anfossi 2008/10/04 23:18


If you mean “columns within columns”, it's implemented in release of 2008-10-08. — Mykola Ostrovskyy 2008/10/08 17:22


Alignment

Having poked at this for a few minutes, I don't believe what you're doing is ever going to produce the alignments you appear to be attempting to achieve. The default settings you add to the Config (local.php) have no alignment styling, at all, and the outputted HTML reflects this. The 0.5em padding assigned to CSS1, CSS2, and CSS3 are not going to produce actual alignments.

It is certainly possible to achieve real alignments by editing the config and adding either a “textAlign:center”, for instance, or a “text-Align:right”. But then those alignments apply to all tables, throughout the entire wiki site, which is not the implied intent. I think that, to allow alignment to be applied to specific tables and columns, you need another layer of manipulation, which would append the appropriate textAlign property to the default style for the given “CSS” column type.

The basic functionality works nicely (in the latest version, at least), though, so thank you for that — DGM2 2008/09/16 01:32


I believe there is a bit of confusion here. The alignment feature has been added to the branched version (release 2008-09-14). The text-align is added to the table cell style attribute at the rendering time. Though, you seems to be talking about the original version of the plugin (the “current release” link up there). Unfortunately Michael doesn't have time at the moment to support the plugin (hence the branch) and the “current release” link is out of date. — Mykola Ostrovskyy 2008/09/28 23:20


Basic Columns

It works if I put NEWCOL rather than ~~NEWCOL~~ (I got ~~ appearing as text). The default language is pt-br.

Please give me all information from both (the correct and incorrect) variants: What did you put in the configuration dialog? What do you put in the text? Please type the complete line with “$conf['plugin']['columns']['kwnewcol'] = …” from your conf/local.php;

In the text

<columns 100% 50% 15% - >
information in column 1 (50% width)
NEWCOL
information in column 2 (15% width)
NEWCOL
information in column 3
</columns>

In the configuration settings, I am going with the default (that is left blank). Check it at Playground.


The same here - NEWCOL works better - ~~ are not displayed. Language is: pl. The settings are default.

There is a small bug in …/columns/lang/en/lang.php - change line 10 from 'NEWCOL' to '~~NEWCOL~~'
Please tell me if the problem is fixed then. You can change it in the preferences too. If you enter ~~NEWCOL~~ it should work, too.
After this you must adjust your pages to the new pattern.

backlinks simply do not work with those links that occure inside a column. The metadata is not updated, the references aren't detected during the rendering, I can't find the way to deal with the problem, did anyone experience this? I am running the latest version of dokuwiki.
Found a bug: when putting links to non-existing pages in one of the columns, the link is red … no problem. But when you now click on it + create the page + go back to the page with the columns … the link remains red. It only turns into the color of a valid pages after editing the page with the columns. I've just tested this on the playground-link provided in the first discussion comment in this page and it's the same there. In other words, not just because of my installation. Is it possible to give this some attention … I plan on using this plugin heavily.

I don't have any idea to fix this. This maybe a problem because i do not understand all of dokuwiki which i use. Any help is welcome. Michael

this is just a caching issue and has nothing to do with the column plugin. Of course, the cache of the column page is not changed if a different (the target) page is edited or created
You'll notice that links on wiki pages are “updated” once a new page was created. To omit that in the column plugin you could use the following in your handler function:
 $renderer->info['cache'] = false; 

Michael Klier 2008/03/13 11:58

Michael, I tried to solve this caching-issue using the way described by you above. Sadly it doesn't work. I tried to add the line in several different ways at several places in the code (although I assume it should be added to the method: function render($mode, &$renderer, $data) before the existing code), but nothing works. Can you maybe explain it a bit more or take a look at the code yourself? — Mischa The Evil 2008/04/16 23:30
Same problem here. In addition, ~~NOCACHE~~ at top of the page doesn't help either.StinkyWinky 2008/05/20 14:26
Please publish your code here (or on your own site), that makes it easier and quicker to review your code without having to go to the trouble of installing the plugin. — Christopher Smith 2008/05/21 11:15
Here is the code … If possible leave a hint using email… this will improve response time… Michael Arlt 2008/06/10 23:39
I would really like to use this plugin more but the cache issue and it having problems outputting properly formatted xhtml is worrisome - Vince 2008/08/21
  • The columns plugin is working unstable with indexmenu. Apache error_log message is shown as following.
[client 220.130.131.238] PHP Fatal error:  Allowed memory size of 16777216 bytes exhausted (tried to allocate 35 bytes) in /var/www/html/dev/inc/parser/parser.php on line 98, referer: http://www.everplast.net/dev/everplast/reinforcedhose/video?do=edit&rev=

After tracing the source code, I guess the error could be from that parser cannot found end tag. Does anyone have workaround solution or patch code?

Jonathan Tsai 2008/07/11 09:26

This is not an error of DokuWiki or the Columns plugin. It is an error caused by the PHP-configuration. Your PHP-setup is limited to use not more then 16MB of memory. This error shows you that the limit has been reached.
See the PHP manual for more info about the related configuration-directive (memory_limit).
Mischa The Evil 2008/07/12 05:21
Actually, the problem is no more appearing after using columns-2008-09-14 branch version. Thanks a lot!
Jonathan Tsai 2008/09/14 22:18

In release 2008-09-14 the backlinks works and the caching issue has gone! Many thanks to Mykola Ostrovskyy! StinkyWinky 2008/09/19 07:59

Is it possible to vertically-align content in the columns? Any tips please email me :) laurence dot diver at gmail dot com — Laurence 2008/10/30 14:49

Language Files

Spanish

lang.php

<?php
/**
 * spanish language file
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Digna González Otero <digna.gonzalezotero [at] gmail [dot] com>
 */
 
$lang['kwcolumns'] = 'columnas'; // define the wiki syntax keywords
$lang['kwnewcol'] =  'NUEVACOLUMNA';  // define the wiki syntax keywords
 
//Setup VIM: ex: et ts=4 enc=utf-8 :
?>

settings.php

<?php
/**
 * Spanish language file
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Digna González Otero <digna.gonzalezotero [at] gmail [dot] com>
 */
 
$lang['css1'] = 'Atributos CSS de la primera columna';
$lang['css2'] = 'Atributos CSS del resto de las columnas';
$lang['css3'] = 'Atributos CSS de la última columna';
$lang['kwcolumns'] = 'Patrón de reconocimiento de Dokuwiki (por defecto: columnas) - Se debe especificar en la página wiki con  &lt;palabra&gt;...&lt;/palabra&gt;';
$lang['kwnewcol']  = 'Patrón de nueva columna de Dokuwiki (por defecto: ~~NUEVACOLUMNA~~)';
 
//Setup VIM: ex: et ts=2 enc=utf-8 :
?>
1) The syntax can be made fully compatible with the original version of plugin by un-checking “Wrap the new column tag” check box in the Configuration Settings.
 
plugin/columns.txt · Last modified: 2008/10/30 15:55 by 217.36.243.20
 

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported

Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate