Archive 1.x:Building structSearch and structBrowse Resultset Templates

Introduction
structSearch and structBrowse OSF-Drupal modules are used to display a series of results coming from the Search OSF Web Service web service endpoint. These two Drupal modules generally use a generic resultset display to display the results from the endpoint.

However, there is a way to template these results. The selection of the template to use to display the results depends on the dataset provenance of the record to template.

Note that this templating mechanism is different from the one used to template records' page using structView.

Location of the Template Files
The structSearch and structBrowse template files are simple  files. These files are located in:



Simple Execution Workflow
What we call a  or a   "template" is in fact a sub-section of the   file. The  files are respectively called by the   or a   files.

Each time a record is being processed to be displayed, the  script get executed. This means that each time  get executed, it is to display a single record within the entire resultset that is getting displayed to the user.

Record's Structure
The  script has access to the   variable. This variable is an array structure that describe the record to be displayed. All the information about that record is available in this structure. The  script only has to select the information it wants to display in the search, or browse, resultset.

The array structure of the  variable is quite simple:

$result = array("dataset" => "http://...",               "type" => array( "type-1" => "", "type-2" => "" ),               "http://predicate-1" => array( array(                                                     "text" => "",                                                      "uri"  => ""                                                    ), array(                                                     "text" => "",                                                      "uri"  => ""                                                    ) ),               "http://predicate-2" => array( array(                                                     "text" => "",                                                      "uri"  => ""                                                    ), array(                                                     "text" => "",                                                      "uri"  => ""                                                    ) ));

Template Selection
What we call a "template" for structSearch and structBrowse is nothing more than a  statement in the   script.

The a template is selected depending on the provenance of the record to display. The provenance of a record is the dataset where it is indexed. You have the possibility to create one "template" per dataset hosted on the instance. Note that you could easily create "sub-templates" for each type of records that is indexed in a given dataset.

If no "template" is defined for a given dataset, then the default "template" will be used to display information about the record. Here is main "template" selection structure for a  file:

Template Creation
Once a new section, for the dataset you want to handle has been added to this list, you have to start the creation of the template. What the template will do is to iterate over the target record's attribute/values, and to generate the  code to inject into the resultset. The code can embed  code or even   embedded widgets.

All the code produced by the template has to be appended to the  variable. It is the content of that variable that will be displayed to the user.

Let's take a look at the following template which displays information about documents describing interviews:

";     break;

This is how structBrowse and structSearch resultsets templates have to be created. In the worse case, the  template will be used.