Currently I've been working with HTML files for each type of object that I'd be displaying on my screen. So for a table I'd have these files:
table.html
<table name="basic_table" class="basic_table">
#DATA#
</table>
table_header.html
<tr class="table-header">
#TABLE_HEADER#
</tr>
table_column_header_row.html
<tr class="column-header-row">
#COLUMN_HEADER_ROW#
</tr>
table_column_header_cell.html
<td class="column-header-cell" nowrap>#COLUMN_HEADER_CELL#</td>
table_cell.html
<td class="cell">#CELL#</td>
As you can see I use #NAME# as my macro this is what I'll replace in my code. I'm also using CSS to handle all of my display values (color, font, etc...). Now I take these files and load them into memory and then regex the strings to build by HTML for output. This gives me the ability to build a table with as many rows/cols as I want. Once I have this table built I put it in the place of another macro that is sitting on my main page layout.
This is just something that I've been playing with and I haven't looked into the speed of it yet, but it should give you an idea of how to implement a system on your own. These files could easily be held in a database and selected when needed. I'd suggest that you look at the PHPLIB code to see what they are doing, I plan on doing that next to see if there are any tricks I can learn.