GURGLE Tutorial: Formatting HTML

Now we want to publish the phone directory database on the web so we need to generate HTML. Essentially the definition file is identical but some different formatting is used for the output, in this case a simple table. The new definition file is included below. Copy it into a file in the same directory as the data source file and call it webphone.grg or download webphone.grg.

%%database "phonedir.txt"
%%define DELIM |
%%define NAMCOL
%%define TEXEXT .html
%%define TITLE Phone Directory
%%equate isprivate(extn)
  if extn'0 = 52 then outputs("PRIVATE")
  else outputs(extn)

In the above we have simply changed the output format to include HTML markup tags. We have added a FOOTER directive so that the tags opened in the HEADER directive are closed properly. We have also changed the extension to be .html. In addition to avoid having to have the title entered twice (once for the TITLE tag and once for the H1 tag) we have created a user defined macro called TITLE with the appropriate value and used this in the text body instead - any %% sequence is expanded with the value of the macro named.

Now we need to gurgle it to produce the web page.

gurgle webphone

If everything worked this will produce an HTML file which will look like the web page webphone.html.


The web page generated is fairly primitive. Try adding some more HTML to liven it up or rearrange the table contents. You could also produce a web page ordered by job title for example.