Go to the first, previous, next, last section, table of contents.
Our purpose is to understand how the template for the administration of urlcatalog was modified to display the urldemo records in a user friendly way. This is the only customization performed for the administration but it is a crucial one. Without customization, the records are displayed in this fashion:
We want them to be displayed in this fashion instead:
The cedit.html template is used to display the current category in the administration interface. The template files are simple HTML files used by the cgi-bin to display their results. Special markers are detected and allow the cgi-bin to:
The _NAME_ tags (always in uppercase, surrounded by underscores) are replaced by values. The HTML comments that look like <!-- start entry --> and <!-- end entry --> define parts of the template that may be included conditionally or repeated to display a list.
For instance, in the following cedit.html template, the part enclosed between <!-- start categories --> and <!-- end categories --> will only be included if the displayed category has at least one sub category. Otherwise it will be completely omitted.
It is therefore very important to take great care not to remove the HTML comments, unless you know exactly what your are doing : they are used to display the results of the cgi-bin.
Here is a commented version of the default cedit.html template:
<title>Edit category _CATEGORY_</title> <center><h3><font color=red>_COMMENT_</font></h3></center> This is a form to search the catalog <center> <form action=_SCRIPT_ method=POST> <input type=hidden name=name value=_NAME_> <input type=hidden name=context value=csearch> <input type=hidden name=mode value=_CONTEXT_> <input type=text size=40 name=text value='_TEXT-QUOTED_'> <input type=submit value='search'><br> </form> </center> These are buttons to perform actions on the category <h3>Edit category _CATEGORY_</h3> <a href='_CENTRYINSERT_'><img src=_HTMLPATH_/images/new.gif alt='Insert a new record and link it to this category' border=0></a> <a href='_CENTRYSELECT_'><img src=_HTMLPATH_/images/link.gif alt='Link an existing record to this category' border=0></a> <a href='_CATEGORYINSERT_'><img src=_HTMLPATH_/images/open.gif alt='Create a sub category' border=0></a> <a href='_CATEGORYSYMLINK_'><img src=_HTMLPATH_/images/plus.gif alt='Create a symbolic link to another category' border=0></a> <a href='_CONTROLPANEL_'><img src=_HTMLPATH_/images/control.gif alt='Control panel' border=0></a> <p> <p> _PATH_ <p> This part is only shown if there are sub categories <!-- start categories --> <h3>Sub categories</h3> <table> <!-- params 'style' => 'table', 'columns' => 2 --> <!-- start row --> <tr> <!-- start entry --> <td> _LINKS_ <a href='_URL_'>_NAME_</a> (_COUNT_) </td> <!-- end entry --> </tr> <!-- end row --> </table> <!-- end categories --> <p> Display the records in this category <h3>Records in this category</h3> <!-- start entry --> <table border=1><tr><td>_LINKS_</td> _DEFAULTROW_</tr></table> <p> <!-- end entry --> This part is only shown if there is more than one page of records (page length is 10 records) <!-- start pager --> Number of pages _MAXPAGES_ <p> _PAGES_ <!-- end pager -->
Since we want to change the display of the records, we only have to modify the relevant portion of the template, that is:
<h3>Records in this category</h3> <!-- start entry --> <table border=1><tr><td>_LINKS_</td> _DEFAULTROW_</tr></table> <p> <!-- end entry -->
The entry part (delimited by the <!-- start entry --> and <!-- end entry --> HTML comments) will be repeated for each record in the category. We want to preserve the _LINKS_ tag that displays the buttons to perform actions on the record (remove, unlink and edit). But we want to change _DEFAULTROW_ to display only the fields of interest. The values of the fields of the urldemo table for the displayed record are available with the following tags : _URL_, _COMMENT_ and _CREATED_. The rationale of the tag substitution when a record is displayed is quite simple: each field name of the record is translated to uppercase and surrounded by underscores. This substitution is done automatically: there is no need to explicitly map the field names to tag names. This is very convenient when you add a new field to the records: the new fields can be displayed by including a new tag matching the field name in the template file.
In addition, a variation of the value is available by appending the -QUOTED string to the field name. This variation replaces HTML reserved characters such as quote (') or double quote (") by the appropriate HTML elements. This is useful to include a value in quotes, for instance. Here is the modified template part:
<!-- start entry --> <table><tr><td>_LINKS_</td> <td> <dt><a href='_URL-QUOTED_'>_COMMENT_</a> <dd> <a href='_URL-QUOTED_'>_URL_</a> <dd> <i><font size=-1>Created _CREATED_</font></i><br> </td></tr></table> <p> <!-- end entry -->
Note that we have used _URL-QUOTED_ instead of _URL_ in the href instruction. The record layout is now exactly what we expect.
Go to the first, previous, next, last section, table of contents.