html-table — output HTML table
Attribute | Pos. | Req. | Default | Description |
---|---|---|---|---|
columns |
Names for the columns, separated by whitespace (\s+ ).
If the th attribute is used, this one is ignored, so the
column names must be passed as the first row of table input data.
|
|||
delimiter |
\t
|
Field delimiter to use if the data is provided in-place (in the tag body) instead of as an array reference. | ||
record_delim |
\n
|
Record delimiter to use if the data is provided in-place (in the tag body) instead of as an array reference. | ||
tr |
Extra arguments for each table row. Any arguments you place
here will render as <tr ARGUMENTS >.
|
|||
td |
Extra arguments for each table cell. Any arguments you place
here will render as <td ARGUMENTS >.
|
|||
th |
Extra arguments for table header. Any arguments you place
here will render as <th ARGUMENTS >.
When this attribute is used, columns is ignored.
|
|||
fc |
Extra arguments for the first table column. Any arguments you place
here will render as <td ARGUMENTS >.
|
|||
fr |
Extra arguments for the first table row. Any arguments you place
here will render as <tr ARGUMENTS >.
|
|||
interpolate | 0 | interpolate input? | ||
reparse | 1 | interpolate output? |
This tag creates an HTML table by auto-inserting the appropriate HTML markup. Table data can either be provided in-place (within the tag body), or passed as a array reference.
The enclosing <table> HTML tag is not included, you have to include it yourself.
Example: Creating an HTML table using in-place data
<table width="90%" border="1"> [html-table fc="bgcolor='red'" fr="bgcolor='blue'" th="bgcolor='yellow'"] title1 title2 title3 r1c1 r1c2 r1c3 r2c1 r2c2 r2c3 r3c1 r3c2 r3c3 [/html-table] </table>
Example: Creating an HTML table using an array reference
[calc] $Scratch->{table} = ( [qw/title1 title2 title3/], ['r1c1', 'r1c2', 'r1c3'], [qw/r2c1 r2c2 r2c3/], [qw/r3c1 r3c2 r3c3/], ); [/calc] <table width="90%" border="1"> [html-table body=`$Scratch->{table}` /] </table>
Since the tag body responds to TABs (\t
) and
newlines (\n
) by default, make sure that the table
input data is not indented.
Separate fields using exactly one field delimiter (one TAB, for example); multiple delimiters in a row will imply empty cells.
Interchange 5.9.0:
Source: code/SystemTag/html_table.coretag
Lines: 14
# Copyright 2002-2007 Interchange Development Group and others # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. See the LICENSE file for details. # # $Id: html_table.coretag,v 1.4 2007-03-30 23:40:49 pajamian Exp $ UserTag html-table addAttr UserTag html-table hasEndTag UserTag html-table PosNumber 0 UserTag html-table Version $Revision: 1.4 $ UserTag html-table MapRoutine Vend::Interpolate::html_table
Source: lib/Vend/Interpolate.pm
Lines: 4646
sub html_table { my($opt, $ary, $na) = @_; if (!$na) { $na = [ split /\s+/, $opt->{columns} ]; } if(! ref $ary) { $ary =~ s/^\s+//; $ary =~ s/\s+$//; my $delimiter = quotemeta $opt->{delimiter} || "\t"; my $splittor = quotemeta $opt->{record_delim} || "\n"; my (@rows) = split /$splittor/, $ary; $na = [ split /$delimiter/, shift @rows ] if $opt->{th}; $ary = []; my $count = scalar @$na || -1; for (@rows) { push @$ary, [split /$delimiter/, $_, $count]; } } my ($tr, $td, $th, $fc, $fr) = @{$opt}{qw/tr td th fc fr/}; for($tr, $td, $th, $fc, $fr) { next unless defined $_; s/(.)/ $1/; } my $r = ''; $tr = '' if ! defined $tr; $td = '' if ! defined $td; if(! defined $th || $th and scalar @$na ) { $th = '' if ! defined $th; $r .= "<tr$tr>"; for(@$na) { $r .= "<th$th><b>$_</b></th>"; } $r .= "</tr>\n"; } my $row; if($fr) { $r .= "<tr$fr>"; my $val; $row = shift @$ary; if($fc) { $val = (shift @$row) || ' '; $r .= "<td$fc>$val</td>"; } foreach (@$row) { $val = $_ || ' '; $r .= "<td$td>$val</td>"; } $r .= "</tr>\n"; } foreach $row (@$ary) { $r .= "<tr$tr>"; my $val; if($fc) { $val = (shift @$row) || ' '; $r .= "<td$fc>$val</td>"; } foreach (@$row) { $val = $_ || ' '; $r .= "<td$td>$val</td>"; } $r .= "</tr>\n"; } return $r; }