Automatic table generation.
Sometimes it's useful to have a little table of data somewhere in your product description.
You can do this by embedding HTML, e.g.:
But this is a real pain for more than a few entries.
How about some simple typing instead. E.g.
Where [( means start the table (and first row).
Comma , separates items on each row
End each row with a round bracket )
Start subequent rows with a round bracket (
End the final row (and the table) with )]
Make sure you have the same mumber of entries on each line.
Implementation.
Edit your Product Layout(s) and replace the variable:
With:
Here's a few lines of CSS (stick them at the bottom of the Actinic Stylesheet) that will prettyfy it.
That's it.
You can even have several tables on the page.
Updated April 2011: Was omitting text before table.
Updated November 2011: Comma wasn't being parsed.
Updated September 2013: Removed sensitivity to newlines in embedded HTML,
Sometimes it's useful to have a little table of data somewhere in your product description.
You can do this by embedding HTML, e.g.:
Code:
!!< <table> <tr> <td>Size</td><td>Small</td><td>Medium</td><td>Large</td> <tr> <td>length</td><td>20</td><td>30</td><td>40</td> </tr> <tr> <td>Weight</td><td>100</td><td>150</td><td>200</td> </tr> </table> >!!
How about some simple typing instead. E.g.
Code:
[(Size, Small, Medium, Large) (Length, 20, 30, 40) (Weight, 100, 150, 200)]
Comma , separates items on each row
End each row with a round bracket )
Start subequent rows with a round bracket (
End the final row (and the table) with )]
Make sure you have the same mumber of entries on each line.
Implementation.
Edit your Product Layout(s) and replace the variable:
Code:
<actinic:variable name="ProductDescription" />
Code:
<actinic:block php="true"> // automatic table generator V1.2 $desc = <<<ENDOFCODE <actinic:variable name="ProductDescription"/> ENDOFCODE; while ( preg_match('/(.*?)&#91;(&#40;.*?&#41;)&#93;(.*$)/s', $desc, $bits) ) // is there at least one table { $tablehtml = '<table id="lpsizes">'; $tablecode = $bits[2]; $rowcount = 0; while ( preg_match('/&#40;(.*?)&#41;(.*$)/', $tablecode, $rbits) ) // each row of table { $tablehtml .= $rowcount++ ? '<tr id="lpother"><td class="lprow">' : '<tr id="lpsizetop"><td class="lprow1">'; $tablehtml .= str_replace('&#44;', '</td><td>', $rbits[1]) . '</td></tr>'; $tablecode = $rbits[2]; } $desc = $bits[1] . $tablehtml . '</table>' . $bits[3]; // reassemble description and look for another table } echo $desc; </actinic:block>
Code:
#lpsizes {background-color:#ccc; text-align:center;} /* Overall table */ #lpsizes td {background-color:#fff; padding:2px;} /* Data cells */ #lpsizetop td {font-weight:bold;} /* Top row */ .lprow1 {} /* Top row, 1st cell */ .lprow {text-align:left;} /* Other rows, 1st cell */
You can even have several tables on the page.
Updated April 2011: Was omitting text before table.
Updated November 2011: Comma wasn't being parsed.
Updated September 2013: Removed sensitivity to newlines in embedded HTML,
Comment