Data Template plugin

Compatible with DokuWiki

  • 2012-01-25 "Angua" unknown
  • 2011-05-25 "Rincewind" yes
  • 2010-11-07 "Anteater" unknown

plugin Adds template capabilities to the data plugin

Last updated on
2011-08-27
Provides
Syntax
Repository
Source
Requires
data

Similar to data, dataloop, templater

Tagged with data, database, listing, template

This plugin adds the possibility to display the structered data of the Data Plugin using templates. Templates can be applied to individual data entries or lists of multiple entries. Additionally, this plugin offers a custom search form, pagination and result caching.

Download and Installation

Download and install the plugin using the Plugin Manager using the URL given above. Refer to Plugins on how to install plugins manually.

Change Log

Template Definition

Templates are separate wiki pages containing placeholders. There are two kinds of placeholders:

  • Placeholders enclosed by @@, e.g. @@Title@@ will be replaced after the template page has been parsed for wiki instructions. The translation rules of the special types of the data plugin still apply. That is, a field with suffix _mail will be rendered as an e-mail link, etc.
  • Placeholders with an additional exclamation in front of the placeholder name, like in @@!Title@@ will be replaced before the template is processed by the Dokuwiki parser. This allows for more fine grained control under some circumstances, like the use of images.

Example

A template definition as in

=== @@Page@@ ===

{{@@!imgname@@?nolink&70 }}
**Phone**: @@phone@@ \\
**E-Mail**: @@email@@

will use whatever value is stored in the field imgname as file name in a standard Dokuwiki image syntax, leading to a left floating picture with phone and email to the right. If the email field was appended by _mail when listed in the cols parameter of the datatemplatelist, it will be correctly rendered as an email link.

Syntax

This plugin provides 3 different syntax blocks. The first two are essentially the same as for the data plugin, but with an added template parameter:

  • The datatemplateentry corresponds to the dataentry of the data plugin. Note that the template should use the names supplied to the headers parameter (if given) as placeholders for the substitutions.
  • The datatemplatelist corresponds to the datalist of the data plugin. Contrary to its “brother”, the datatemplatelist also supports pagination.

The value of the template parameter is a Dokuwiki page containing the template definition, as discussed above. A datatemplateentry could for example look like this:

---- datatemplateentry member ----
template   : tpl_member
firstname  : Christoph
lastname   : Clausen
type       : PhD Student
active     : yes
addr       : GAP-Optique \\ Rue de l'Ecole de Medecine 20 \\ CH-1211 Geneve 4
----

Filter Form

The filter form adds new functionality to the data and datatemplate plugins. It can be used on pages where there is already a datatable, datalist or datatemplatelist. An example of the syntax looks like this:

---- filterform ----
fields: Any, Title, Journal, Author, Volume, Page, Year, Abstract
----

The single parameter fields is turned into a dropdown list when the page is rendered. Its value is a list of column names or headers. Next to the dropdown list is a text field. When the form is submitted, only those data entries are displayed, where the column selected in the dropdown box contains the text in the text field. This effectively corresponds to adding a line like filter: Title~*weather* inside the source of e.g. the datatable.

It is possible to add more and more filter criteria by repeatedly submitting the form. Also, applied filters can later be removed individually.

Demonstration

For a demonstration, see for instance the Publications page of the Group of Applied Physics at the University of Geneva. There, both the datatemplate list and the filter form can be seen in action. Each item in the list is a datatemplate entry (created by a separate plugin that accepts BibTeX as input). The Members page is equally based on this plugin.

A technical note about caching

The data plugins stores its data as simple key-value pairs in an SQLite database. While this leads to a lot of flexibility, there is a disadvantage when querying the data from the database. To obtain something that looks like a result from “normal” SQL tables, the data plugin tailors together a series of JOIN operations, which can be very time consuming. To give some numbers, a single request with about 300 result items, as is the case for the list of publications mentioned above, took several seconds to resolve. Even though this does not seem too bad, it quickly becomes frustrating, when filtering and page navigation lead to several such requests in a row.

A simple caching technique in the datatemplate list significantly speeds up page queries. This essentially works as follows:

  1. Validation: A simple query, without pagination and filters added via GET or POST, is performed, containing only the ids of the pages containing the data that is asked for. Since this query only involves a very limited number of JOIN operations, it is reasonably fast. The modification times of the files containing these pages are then checked, and if none of them is newer than the cache, the cache is assumed valid. A separate check removes cache entries corresponding to pages that no longer exist.
  2. Building: In the case that the cache needs to be rebuilt, the full query is performed. However, to avoid the creation of too many cache files, and that the same data is cached repeatedly, any filters added via GET or POST, as well as limits and offsets for pagination, are removed.
  3. Storage: The cache file is stores in the cache directory of Dokuwiki. The filename is hash of the stripped down SQL query string.

One can force a rebuild of the cache by using the Dokuwiki purge mechanism.

Shortcomings

In the current state, this plugin leaves room for improvements. Some of the currently known issues are

  • The plugin is not able to detect circular dependencies in the rendering of templates.
  • If a template contains relative links, these are not corrected.
  • The rendering of the templates is not cached.
  • If the use of a template gives the first header of the page, the page title is not updated correspondingly.
  • There are some problems with the simultaneous use of the include plugin.
  • Cache files that are no longer in use are not detected and deleted automatically.

However, there are no promises that these (or other) issues will be addressed in future releases.

Acknowledgements

This plugin was inspired by the dataloop plugin by Martyn Eggleton. Much of the template rendering code is based on the templater plugin by Jonathan Arkell.

Bugs, Feature Requests and Patches

Please submit bugs and feature requests in the issue tracker linked at the top.

plugin/datatemplate.txt · Last modified: 2012/01/18 19:28 by Aleksandr
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate