![]() |
Frontier Tutorials / Writing Table Renderers / The Easy Way |
The easy way is not so obvious:
on RenderTableAsXXX( tableAdr )
local
outText = ""
« Put tableAdr in page table
« Get template
« Expand macros in template
return( outText )
Looks easy, and it's easy to work with. It may not be completely obvious what it's doing, however. To clarify it, let's look at a closer-to-real implementation of the script:
on RenderTableAsXXXX( tableAdr )
« Instructions:
« Copy this script to your tools table.
« Change both instances of XXXX to the name of your choice.
« Change the name of this script to match.
« Create a template in the #templates subtable with the name used in templateAdr, below.
« Template may be an outline or wptext.
« In the template, refer to items in the table as {tableToRender^.itemname}.
on GetPageTbl()
try
return( html.getPageTableAddress() )
return( @websites.["#data"] )
local
pageTbl = GetPageTbl()
templateAdr = @pageTbl^.templates^.XXXX
template = ""
pageTbl^.tableToRender = tableAdr
« Recognize and honor embedded directives from the template.
template = html.runDirectives( string( templateAdr^ ), pageTbl )
return( html.processMacros( template ) )
This is actually the script template I use to create table renderers. (I've included it in this page for your convenience.) I copy it into the #tools table, rename it to, for example, RenderTableAsEvent, and change every occurance of XXXX to Event. The script is then complete and fully functional.
This script inserts the address of the table to be rendered (tableAdr) into the page table so that the table's entries are visible to the website framework scripts--and to templates. It then gets a custom template (used solely by this renderer), calls html.runDirectives() to extract any directives embedded in the template, calls html.processMacros() to expand all macros in the template, and returns the result to the caller. The caller turns out to be html.tenderRender, which substitutes the returned result into the page template as the bodytext.
To use this script, you need a corresponding template in the #templates table. It can be a string, outline, or wptext.
The template for the RenderTableAsEvent table renderer would be named--reasonably enough, I think--Event, and might look like this:
<table>
<tr valign=top>
<td><b>{tableToRender^.date}</b></td>
<td>{tableToRender^.name}</td>
</tr>
<tr>
<td><b>Time</b></td>
<td>{tableToRender^.time}</td>
</tr>
<tr>
<td><b>Contact</b></td>
<td>{tableToRender^.contact}</td>
</tr>
<tr>
<td colspan=2>{tableToRender^.directions}</td>
</tr>
</table>
Notice that this renderer template does not contain any of the page framing macros you're accustomed to seeing in website templates. This template only applies to the page content. It describes the formatting of what will become just the bodytext in the page template. So you don't have to worry about page headers, page footers, and such.
![]() |
![]() |
This page is a Fat Page. It includes the above script(s), encoded by and for Frontier. To retrieve the script(s), save the page as source text and open it using the File->Open command. |
|
---|