Frontier Tutorials / Writing Table Renderers / The Easy Way

The Easy Way

The easy way is not so obvious:

on RenderTableAsXXX( tableAdr )
space picturelocal
space pictureoutText = ""
space picture« Put tableAdr in page table
space picture« Get template
space picture« Expand macros in template
space picturereturn( 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 )
space picture« Instructions:
space picture« Copy this script to your tools table.
space picture« Change both instances of XXXX to the name of your choice.
space picture« Change the name of this script to match.
space picture« Create a template in the #templates subtable with the name used in templateAdr, below.
space picture« Template may be an outline or wptext.
space picture« In the template, refer to items in the table as {tableToRender^.itemname}.
space pictureon GetPageTbl()
space picturetry
space picturereturn( html.getPageTableAddress() )
space picturereturn( @websites.["#data"] )
space picturelocal
space picturepageTbl = GetPageTbl()
space picturetemplateAdr = @pageTbl^.templates^.XXXX
space picturetemplate = ""
space picturepageTbl^.tableToRender = tableAdr
space picture« Recognize and honor embedded directives from the template.
space picturetemplate = html.runDirectives( string( templateAdr^ ), pageTbl )
space picturereturn( 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>
space picture<tr valign=top>
space picture<td><b>{tableToRender^.date}</b></td>
space picture<td>{tableToRender^.name}</td>
space picture</tr>
space picture<tr>
space picture<td><b>Time</b></td>
space picture<td>{tableToRender^.time}</td>
space picture</tr>
space picture<tr>
space picture<td><b>Contact</b></td>
space picture<td>{tableToRender^.contact}</td>
space picture</tr>
space picture<tr>
space picture<td colspan=2>{tableToRender^.directions}</td>
space picture</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.

You thought that was easy? There's an even easier way!

fatpage picture space picture 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.


Tutorial Contents
Writing Table Renderers
What Is A Table Renderer
Anatomy of a Table Renderer
The Hard Way
The Easy Way
The Easiest Way
About the Author