Home | SourceForge | Documentation | FAQ | What's New | To-Do List | Forums | Download | Contact

Sparse - Quick Templates

All of the template examples we've seen so far seem to have a lot of HTML code in common - in fact, they're all inside HTML tables. Most queries generally will be inside a table of some kind. Taking that into account, and using the fields attribute introduced in the previous section, Sparse can recreate an entire template just from the sqlquick tag. This tag is primarily identical to sqltemplate. An example:

  <sqlquick type="edit"
   fields="employeeID,, AS mname, concat(e.address, AS address"
    tables="employees AS e, managers AS m"
    constraints="WHERE AND mname != 'John Smith'">

Sparse will expand this to the following:

  <sqltemplate database="myDB" type="edit" tables="employees AS e, managers AS m"limit="10" constraints="WHERE AND mname != 'John Smith'">
       <td><sqlfield name="employeeID" /></td>
       <td><sqlfield name="" /></td>
       <td><sqlfield name=" AS mname" /></td>
       <td><sqlfield name="concat(e.address, AS address" /></td>
       <td><sqlaction type="edit" /><sqlaction type="delete" /><sqlaction type="reset"</td>
     <tr><td colspan="5"><sqlnavigation /></td></tr>

As you can see, the name of each field is turned into the title of the column, so use aliases to give your columns nice names. Each field becomes an sqlfield tag inside the sqlrow tag. Correct sqlaction tags are also added. Et voila! One tag gives you a full-fledged template which allows you to edit, delete, and navigate through your data!

Quick templates always have a table tag, so they let you set the class or style of the table by putting those attributes on the sqltemplate tag. The best thing is to have a CSS class that looks like this:

table.template1 {border-collapse: collapse;}
table.template1 td, table.template1 th {border: 2px solid black;}

And then set the class of the sqlquick tag to template1. This will make the table look more like a regular HTML table.

One more note: The only way to have "mass update" tables here is to change the template type to mass-edit. (Normally the type is automatically changed when an edit button is outside the sqlrow, but you don't have that luxury here.)

Finally, you can be even quicker by leaving out the fields attribute entirely. Sparse will then display all fields in the table(s) you give it. The name of each column will be the name of the field with the first letter capitalized.

You can give sqlquick a few more attributes you couldn't give to sqltemplate: you can tell it where (or whether) to print search forms, navigation, sort forms, and row errors.


Quick Templates are just that - quick - so there are things you can't do. For example, you can't have any kind of fine-tuning of data (input validation, changing data before display or before update) or error placement. Nor can you change how the action buttons look, or use any enumsets other than default ones. Still, they're a great way to write your templates if you don't need anything complex. Thirty seconds gets you a full application!

Previous: Advanced Queries | Quick Templates | Next: Enumsets