I cant make this work on my forum, it says something about an invalid form being used for my BBCode.Christian Ankerstjerne wrote:To the moderators: I'm not sure where to post this - if this is wrong, feel free to move it to a more appropriate section.
I know that there's a custom BBCode table tutorial out there, but I thought I'd share my take on it anyway.
Custom BBCode
BBCode usage linesHTML replacement linesCode: Select all
[table]{TEXT}[/table] [trow]{TEXT}[/trow] [theader]{TEXT}[/theader] [tmultiheader={NUMBER}]{TEXT}[/tmultiheader] [tcell]{TEXT}[/tcell] [tmulticell={NUMBER}]{TEXT}[/tmulticell]
Suggested help lines (optional)Code: Select all
<table class="customtable">{TEXT}</table> <tr>{TEXT}</tr> <th>{TEXT}</th> <th colspan="{NUMBER}">{TEXT}</th> <td>{TEXT}</td> <td colspan="{NUMBER}">{TEXT}</td>
CSS for style sheet (optional)Code: Select all
Creates a table Table row (only for use inside a [table]) Table header (only for use inside a [trow]) Table header, spanning over multiple columns (only for use inside a [trow]) Table cell (only for use inside a [trow]) Table cell, spanning over multiple columns (only for use inside a [trow])
Sample usageCode: Select all
table.customtable { border-collapse: collapse; } table.customtable td, table.customtable th { border: 1px solid #000000; } table.customtable td[colspan], table.customtable th[colspan] { text-align: center; }
BBCodeVisual renderingCode: Select all
[table] [trow] [tmultiheader=4]Table example[/tmultiheader] [/trow] [trow] [theader]Table header 1[/theader] [tcell]Table cell 1[/tcell] [tcell]Table cell 2[/tcell] [tcell]Table cell 3[/tcell] [/trow] [trow] [theader]Table header 2[/theader] [tmulticell=2]Table cell 4[/tmulticell] [tcell]Table cell 5[/tcell] [/trow] [/table]
NotesCode: Select all
+------------------------------------------------------------+ | Table example | +---------------+--------------+--------------+--------------+ |Table header 1 | Table cell 1 | Table cell 2 | Table cell 3 | +---------------+--------------+--------------+--------------+ |Table header 2 | Table cell 4 | Table cell 5 | +---------------+-----------------------------+--------------+
You might want to style the tables further, above I have only included the style for centering cells spanning more than one cell width (this won't work with IE6, though, but you can add an additional class and CSS declaration to take care of that), as well as added a border (I made it black in the example, change to suit your forum's style).
I didn't include the THEAD and TBODY elements, since few users would know how to use them properly anyway. I didn't use TR, TH and TD for the BBCode, as I figure the names I've used would be easier to understand for the users who is not familiar with HTML. Also, this allows for easier coding of cells spanning more than one cell width (the other solution I've seen made the COLSPAN-declaration mandatory for all cells, resulting in a lot of verbose output (i.e. TD COLSPAN="1").
Feel free to use this BBCode on your forum.