Database Tour Documentation Contents Index

Example of Using Template in HTML Export

Top Previous Next

In this example we will learn how to use HTML template for exporting data (including images), conditionally highlighting the data, and aggregating the data.

Suppose we have a certain table with product list, which is changed from time to time...

Table to export

...and we want to export it on a regular basis to HTML page from our website using Database Tour:

Target web page

First, we need to prepare a template for the target web page. We either use an existing html file for this, or create a new one, making all necessary design.

In the template, we create specific dynamic areas to be filled during the export process.

1. Prepare Title html attribute (<Title> tag). It will be filled from Document title export option. Use vle_expr macro for this:


2. Prepare the topic title. It will be filled from Document title export option. Use vle_expr macro for this:

<h2><span style="color: #993300"><!--vle_expr(doc_title)--></span></h2>

3. Prepare the table. It will be filled from the source dataset. It is the most complex task.

Below the table header row, put vle_loop_start and vle_loop_end macros. Between them, put html elements and vle_expr macros, which will form one data row in the target table. All these elements will be ouptutted to target document for each source dataset row.

Here, we will add also images from the database in the first column, and will use conditional highlighting the data in the second column by using bold font (<b> tag) for sizes which are larger than 1000 Kb.

<!--vle_loop_start(1, 'each_row_in_dataset', 0, 0)-->
<td width="34%" height="24" class="notes">
<!--vle_expr('<a href="' + dataset_field_val(1, 'webpage') + '">')-->
dataset_field_val(1, 'descript'),

<b><!--vle_expr(dataset_field_val(1, 'title'))--></b> </td>
<td width="11%" height="24" class="notes"><div align="RIGHT">
dataset_nvl(1, 'sizekb', 0) > 1000,
'<b>' + to_string(dataset_field_val(1, 'sizekb')) + '</b>',
to_string(dataset_field_val(1, 'sizekb'))

<td width="15%" class="notes_mini_thick_line"><!--vle_expr(dataset_field_val(1, 'category'))--></td>
<td width="16%" height="24" class="notes"><!--vle_expr(dataset_field_val(1, 'language'))--></td>
<td height="24" class="notes_mini_thick_line"><!--vle_expr(dataset_field_val(1, 'descript'))--></td>

4. Add a table footer for totals. It will be filled with aggregated values calculated during the export process.

We should place it above of the table closing tag.

<td height="32" bgcolor="#FFFFBB" class="notes"><strong>Total size:</strong></td>
<td height="32" bgcolor="#FFFFBB" class="notes"><strong>
<div align="right"><!--vle_expr(dataset_sum(1, 0, 'SizeKB'))--></div></strong></td>
<td height="32" colspan="3" bgcolor="#FFFFBB" class="notes">
Total products:&nbsp;<span style="color: #0000FF"><!--vle_expr(dataset_row_count(1, 0))--></span>,
and in your language:&nbsp;<span style="color: #0000FF">
1, 0, 'language', 'pos(''Eng'', dataset_field_val(1, ''language'')) > 0'

</strong> </td>

Now, the template is ready. Name it products_template.html, for example.

In browser, the main part of the template will look something like this:

HTML template

Then, back to the program and prepare export options. Click Export button. The Export dialog will appear. Specify the target file, template file, and document title:

Export settings

Now, click Export and check the result. In browser, the main part of the target page will look as following:

HTML template filled with data

We can get such a result also by using the command line:

exptizer.exe /export /ExportType=HTML
"/DocTitle=Our Software Products"
/ExportStepNo=1 /TemplateFile=C:\MyWebSite\products_template.html
/SrcDBInterface=ado /SrcDBKind=DSN /SrcDBDriver=MySQL
/SrcDB=MySQLDB /SrcTableName=software_list

or via the action file with the following content:

"/DocTitle=Our Software Products"

See also

 Exporting to HTML Using Template

 Expression Engine