Creating new pages from queries

Inside a {*foreach*}, you can now do a {*makepage*}

It could look like this:

{* foreach r in “DbTableGenTest:select * from Contacts” *}
{* makepage p “filename.html” *}
{* endpage p *}
{* next *}

The filename is probably going to be based on the query, so you can do this:

{* makepage p “contact”+r.id+”.html” *}

r is the variable from the foreach and id is a field in the query. String together quoted strings and fields with +.

Inside the makepage/endpage, you must have a full HTML file, like this:

{* foreach r in “DbTableGenTest:select * from Contacts” *}
{* makepage p “filename.html” *}
<html><head></head><body>
Name: {* r.name * }
</body></html>
{* endpage p *}
{* next *}

Note that you can reference the foreach query inside the makepage.

Using foreach on subpages

You can even get a foreach to execute on the new page (it will be processed with HTML DBScript after it is created).  The way you do that is a little funky and you have to realize that the script in the made page is getting processed twice (once on the outer page and again on the made page).

Presume that you have two tables, Contacts and Children (each contact has multiple children).  I want a list of contacts each going to a detail page that has a list of children.

Inside the made page, the foreach needs to be escaped out, like this

{{**}* foreach … *}

The embedded {**} is removed on the first pass, putting

{* foreach …. *}

Into the new page, which is then processed.