DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:datatemplate

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
plugin:datatemplate [2012-07-08 15:36] – added dependency Klap-inplugin:datatemplate [2022-12-06 11:59] (current) – [Data Template Plugin] Search for new maintainer(s) Cyrille37
Line 1: Line 1:
-====== Data Template plugin ======+====== Data Template Plugin ======
  
 ---- plugin ---- ---- plugin ----
 description: Adds template capabilities to the data plugin description: Adds template capabilities to the data plugin
-author     : Christoph Clausen +author     : Cyrille Giquello, Christoph Clausen 
-email      : christoph.clausen@gmail.com+email      : cyrille@giquello.fr
 type       : syntax type       : syntax
-lastupdate : 2011-08-27 +lastupdate : 2016-08-03 
-compatible : rincewind+compatible : 2017-02-19 "Frusterick Manners", 2016-06-26 "Elenor Of Tsort", 2015-08-10 "Detritus", Rincewind, Weatherwax
 depends    : data, sqlite depends    : data, sqlite
 conflicts  conflicts 
Line 13: Line 13:
 tags       : data, database, listing, template tags       : data, database, listing, template
  
-downloadurl: https://github.com/ccl/dokuwiki-plugin-datatemplate/zipball/master +downloadurl: https://github.com/Cyrille37/dokuwiki-plugin-datatemplate/archive/2016-08-03.zip 
-bugtracker : https://github.com/ccl/dokuwiki-plugin-datatemplate/issues +bugtracker : https://github.com/Cyrille37/dokuwiki-plugin-datatemplate/issues 
-sourcerepo : https://github.com/ccl/dokuwiki-plugin-datatemplate/+sourcerepo : https://github.com/Cyrille37/dokuwiki-plugin-datatemplate/
 donationurl:  donationurl: 
 ---- ----
  
-This plugin adds the possibility to display the structered data of the [[data|Data Plugin]] using templates. Templates can be applied+:?: :!: [[https://github.com/Cyrille37/dokuwiki-plugin-datatemplate/issues/16|Search for new maintainer(s)]]  :!: :?: 
 + 
 +This plugin adds the possibility to display the structured data of the [[data|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. to individual data entries or lists of multiple entries. Additionally, this plugin offers a custom search form, pagination and result caching.
 +
 +News: The original author, Christoph Clausen, cannot maintain anymore the plugin, so I adopt it ;-) Thanks a lot to him to have built first steps and accepted the adoption in 2016 august.
  
 ===== Download and Installation ===== ===== Download and Installation =====
  
-Download and install the plugin using the [[plugin|Plugin Manager]] using the URL given above. Refer to [[:Plugins]] on how to install plugins manually.+Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually.
  
 ==== Change Log ==== ==== Change Log ====
  
-{{rss>http://github.com/feeds/ccl/commits/dokuwiki-plugin-datatemplate/master date}} +  * 2016-08-02 Add translation for list navigation links and filter button 
 +  * 2016-08-02 Cyrille Giquello adopted the plugin with Christoph Clausen agreement 
 +  * 2016-07-11 fix deprecated constructor calls 
 + 
 +Last github commits on release [[https://github.com/Cyrille37/dokuwiki-plugin-datatemplate/tree/2016-08-03|2016-08-03]]. 
 + 
 +{{rss>https://github.com/Cyrille37/dokuwiki-plugin-datatemplate/commits/2016-08-03.atom date}} 
  
 ===== Template Definition ===== ===== Template Definition =====
 +
 Templates are separate wiki pages containing placeholders. There are two kinds of placeholders: 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 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.+  * 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. 
 +  * :!: Placeholders with capital letter do not work in the current version  --- [[user>mcgumbel|mcgumbel]] //2014-09-25 18:32//
  
 ==== Example ==== ==== Example ====
 +
 A template definition as in A template definition as in
-<code> + 
-=== @@Page@@ ===+<code - tpl_member> 
 +{{@@!imgname@@?nolink&200 }} 
 +  * **Position**: @@type@@ 
 +  * **Address**: \\ @@!addr@@ 
 +  * **Phone**: @@phone@@ 
 +  * **E-Mail**: @@email@@ 
 +</code> 
 + 
 +OR 
 + 
 +<code - tpl_memberlist
 +=== @@%title%@@ ===
  
 {{@@!imgname@@?nolink&70 }} {{@@!imgname@@?nolink&70 }}
Line 44: Line 68:
 **E-Mail**: @@email@@ **E-Mail**: @@email@@
 </code> </code>
-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.+ 
 +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 ===== ===== 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 ''[[data#data_entry_(input)|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 ''[[data#data_list_(output)|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:+This plugin provides **3** different syntax blocks: 
 +  - ''datatemplateentry'' 
 +  - ''datatemplatelist'' 
 +  - ''filterform'' 
 + 
 +The first two are essentially the same as for the data plugin, but with an added ''template'' parameter. 
 + 
 +==== datatemplateentry ==== 
 + 
 +The ''datatemplateentry'' corresponds to the ''[[data#data_entry_(input)|dataentry]]'' of the data plugin. Note that the template should use the column names supplied to the ''headers'' parameter (if given) as placeholders for the substitutions. 
 + 
 +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: 
 <code> <code>
 ---- datatemplateentry member ---- ---- datatemplateentry member ----
-template   : tpl_member +template    : tpl_member 
-firstname  : Christoph +firstname   : Christoph 
-lastname   : Clausen +lastname    : Clausen 
-type       : PhD Student +type        : PhD Student 
-active     : yes +active      : yes 
-addr       : GAP-Optique \\ Rue de l'Ecole de Medecine 20 \\ CH-1211 Geneve 4+phone       : 123-987654 
 +email_mail  : example@example.com 
 +imgname_img : pics:userpicture.jpg 
 +addr        : GAP-Optique \\ Rue de l'Ecole de Medecine 20 \\ CH-1211 Geneve 4
 ---- ----
 </code> </code>
 +
 +Not all types supported by the data plugin are implemented. Current supported types are:
 +  * ''page'' -- the entry is treated as Wiki pagename and will be linked in output
 +  * ''title'' -- like page, but an additional display title can be given separated by a pipe
 +  * ''pageid'' -- the input is the caption for a link to the data entry page
 +  * ''nspage'' -- like page, but the column name is treated as namespace for the link.
 +  * ''mail'' -- Eventually additional text (separated by space) is used as name that will be linked with the given email address
 +  * ''url'' -- the value will be treated as external link
 +  * ''img'' -- the input is assumed to be a image URL or local media id and is displayed as given
 +  * ''wiki'' -- render the input as wikitext
 +
 +When no type is given the input is handled as wiki text.
 +
 +==== datatemplatelist ====
 +
 +The ''datatemplatelist'' corresponds to the ''[[data#data_list_(output)|datalist]]'' of the data plugin. Contrary to its "brother", the ''datatemplatelist'' also supports pagination.
 +
 +Example syntax:
 +
 +<code>
 +---- datatemplatelist ----
 +template: tpl_memberlist
 +cols    : %title%, imgname, phone, email_mail
 +sort    : firstname
 +filter  : %pageid%~members:*
 +and     : type=Group Leader
 +and     : active=yes
 +----
 +</code>
 +
 +This list all the pages in ''members:'' that satisfy the conditions set in this syntax and uses the ''tpl_memberlist'' page to render a nice entry in the list for each page. When column names of the ''cols'' parameter are appended by a type e.g. ''_mail'', this type is used when rendering this value.
 +
 +The ''cols'' parameter defines the placeholders available in the template. For the example above, you can use e.g. ''@@imgname@@'' in your template. The available column names in ''cols'' corresponds with the column names used in the data entries. However there are some additional columns available for adding extra columns to the data list:
 +
 +^Column name ^ Appearance^ Placeholder  ^
 +| %title%   | The first headline of a page, which has a link to data entry page. | @@%title%@@   |
 +| %pageid%  | The page name, which has a link to data entry page | @@%pageid%@@  |
 +| %class%   | The class of a data entry | @@%class%@@   |
 +| %lastmod% | The date of last modification of the entry | @@%lastmod%@@ |
 +
 +Beside the columns you list in ''cols'' there is one column always available, that is ''%pageid%''.
 +
 +=== Deprecated ===
 +
 +Untill 18 May 2013 the special placeholders above where available by their localized title. To simplify their usage, you can now only use the column names as mentioned above.
 +
 +^Column name ^ Title depending on localization((English localization listed here))\\ as used in placeholder^
 +|%title%   |@@Page@@|
 +|%pageid%  |@@Page Name@@|
 +|%class%   |@@Page Class@@|
 +|%lastmod% |@@Last Modified@@|
  
 ==== Filter Form ==== ==== 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: 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:
 +
 <code> <code>
 ---- filterform ---- ---- filterform ----
Line 70: Line 160:
 ---- ----
 </code> </code>
-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''.+ 
 +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 //that are present in the "cols" data parameter//. There is the magic "Any" filter which permits to filter with all data displayed columns. 
 + 
 +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. It is possible to add more and more filter criteria by repeatedly submitting the form. Also, applied filters can later be removed individually.
    
 ===== Demonstration ===== ===== Demonstration =====
-For a demonstration, see for instance the [[http://www.gap-optique.unige.ch/wiki/publications:start|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 [[http://www.gap-optique.unige.ch/wiki/members:start|Members page]] is equally based on this plugin.+ 
 +For a demonstration, see for instance the [[http://www.unige.ch/gap/quantum/publications:start|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 [[http://www.unige.ch/gap/quantum/members:start|Members page]] is equally based on this plugin, the members are listed by ''datatemplatelist'' and the member pages contains a ''datatemplateentry''. 
 + 
 +As another example I am using this plugin on my personal website to provide a pretty index page for a collection of [[http://adam.nz/recipe|recipes]] and [[http://adam.nz/library|documents]]. (This was broken for a while after a Doku upgrade, but not that the plugin has been fixed it's working again). -- Adam
  
 ===== A technical note about caching ===== ===== 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 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 disadvantage when querying the data from the database. To obtain something that looks like a result from "normal" SQL tables, the data plugin
Line 85: Line 184:
   - **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.   - **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.
   - **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.   - **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.
-  - **Storage:** The cache file is stores in the cache directory of Dokuwiki. The filename is hash of the stripped down SQL query string.+  - **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 [[devel:caching#purging_the_cache|Dokuwiki purge mechanism]].+One can force a rebuild of the cache by using the [[devel:caching#purging_the_cache|DokuWiki purge mechanism]].
  
 ===== Shortcomings ===== ===== Shortcomings =====
 +
 In the current state, this plugin leaves room for improvements. Some of the currently known issues are 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.   * The plugin is not able to detect circular dependencies in the rendering of templates.
Line 101: Line 201:
  
 ===== Acknowledgements ===== ===== Acknowledgements =====
-This plugin was inspired by the [[dataloop|dataloop plugin]] by Martyn Eggleton. Much of the template rendering code is based on the + 
-[[templater|templater plugin]] by Jonathan Arkell.+First years, until 2016 august, of this plugin was released and maintained by Christoph Clausen. 
 + 
 +This plugin was inspired by the [[dataloop|dataloop plugin]] by Martyn Eggleton. Much of the template rendering code is based on the [[templater|templater plugin]] by Jonathan Arkell.
  
 ===== Bugs, Feature Requests and Patches ===== ===== Bugs, Feature Requests and Patches =====
  
 Please submit bugs and feature requests in the issue tracker linked at the top. Please submit bugs and feature requests in the issue tracker linked at the top.
- 
plugin/datatemplate.1341754589.txt.gz · Last modified: 2012-07-08 15:36 by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki