AdvancedTableDirectives
Questions answered by this recipe
- How to put a caption on a table using table directives?
- How to create headers on a table using table directives?
- Why are there more features in ordinary tables than table directives?
- How to apply zebra formatting to tables created with table directives?
- Can I nest tables inside of other tables?
Description
This recipe will adds Directives and provides abilities for nested tables and for horizontal and vertical zebra tables.
A demo of the capabilities is at URL: http://gnuzoo.org/test/AdvancedTableDirectives - no longer available -
Two other recipes which enhance AdvancedTableDirectives are SourceCodeHorizontalLines and SimplifiedAdvancedTableDirectives.
Currently tables have 3 capabilities that table directives do not have. "<header>", "<caption>" and automatic zebra formatting (see FormattingTables) of rows and columns (there are probably others too). PMWiki Table Directives cannot be nested and include only 4 directives. (:table:) (:cell:) (:cellnr:) (:tableend:)
(:head:) & (:headnr:)
:) This recipe will adds these directives:
(:caption:) - caption (:head:) - header cell (:headnr:) - header cell new row (:row:) - row (:cellc#:) - current column number (:cellr#:) - current row number (:celli#:) - auto-incrementing number - incremented when used (:celli#1:) - (:celli#2:), ... (:celli#9:)]] - seperate auto-incrementing numbers (:cellic#:) - auto-incrementing column number - incremented when used, set to 1 on new row (:cellir#:) - auto-incrementing row number - incremented when used in a new row, but not in same row
A demo of the capabilities is at URL: http://gnuzoo.org/test/AdvancedTableDirectives
Installing
Copy AdvancedTableDirectives.phpΔ to your cookbook directory
- For PHP 5.5, 7.2 or newer please get AdvancedTableDirectives-php72.phpΔ instead and rename it to remove the "-php72" part.
In your config.php enter:
or in your farmconfig.php enter:
$FarmD
/cookbook/AdvancedTableDirectives.php");
Notes
All directives follow the same syntax: (: directive (attributes) :)
For example:
(:caption color=red :)This is the caption text (:head bgcolor=lightblue :)This is header text
Automatic zebra formatting (mostly used for coloring) can be applied as well. In this example the table header row will have a lightblue background and the other table rows will have alternating lightgreen and lightyellow background colors.
$TableRowIndexMax = 2; $TableRowAttrFmt = "class='row\$TableRowIndex'" ; $TableCellAttrFmt = "class='col\$TableCellCount'";
table th { background-color:#99ccff; } table tr.row1 { background-color:#ffff99 ; } table tr.row2 { background-color:#ccffcc; } table td { line-height: 12px; }
For vertical zebra tables there are 2 new variables - TableCellIndexMax and $TableCellIndex
$TableCellIndexMax = 3; $TableRowIndexMax = 2; $TableRowAttrFmt = "class='row\$TableRowIndex'" ; $TableCellAttrFmt = "class='col\$TableCellCount colidx\$TableCellIndex'";
table td.colidx1 {background-color:#ffff99;} table td.colidx2 {background-color:#ccffcc;} table td.colidx3 {background-color:#FFC0CB;}
For more information about formatting tables see FormattingTables.
About Merging Attributes
Attributes can automatically be placed onto directives using $TableCellAttrFmt
and/or $TableRowAttrFmt
. This can conflict with attributes specified directly on the directive itself. (This is one of several reasons normal Table Directives dot not use $TableCellAttrFmt
and/or $TableRowAttrFmt
). This recipe will merge only the class element - meaning it will eliminate duplicates and setup multiple class attributes as a space separated string (like this - class='classname1 classname2 classname3' - per W3C recommendation). I have chosen not to merge other attributes because it would make the code very complicated and slower and most other attributes can be set in a cascading style sheet. Any attributes besides class that are designated in $TableCellAttrFmt
and/or $TableRowAttrFmt
are simply appended to the directive attributes and not merged.
Release Notes
- Version: 3.1 - Adjust FmtPageName() function use to be just like PmWiki
- Version: 3.0 - Major upgrade - Added class attribute merge with automatic zebra tables, added global variable $TableCellIndexMax, added internal variable $TableCellIndex, made recipe faster, added variable $RecipeRunAction to determine when to run the recipe, more
- Version: 2.2 - better regular expression, added <:block> for each table start
- Version: 2.1 - Execute only for specific actions
- Version: 2.0 - Should be faster
- Version: 1.1 - Added RecipeInfo
- Version: 09 28 2006 2:38 PM CST
<td>
and <tr>
tags get crossed.
- Version: 09 19 2006 7:09 AM CST
See Also
Contributors
Comments
See discussion at AdvancedTableDirectives-Talk
User notes +1: 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.