Table of Contents

MyTemplate Plugin

Compatible with DokuWiki

2010-11-07 "Anteater", 2011-05-25 "Rincewind", 2012-01-25 "Angua"

plugin Complex page templates

Last updated on
2012-05-14
Provides
Action
Repository
Source

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to pagetemplater

Tagged with editing, include, meta, page, template

Download and Installation

Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.

Syntax and Usage

The plugin allows you to separate the structure of a wiki page and the data contained within. This allows you to have multiple data pages referencing the same structure page. Technically, you can also combine several structure pages.

I will continue to use the term “structure page” for the pages that contain dokuwiki code and placeholders for data and “data page” for those that contain the actual data that will be inserted into those placeholders. Both types of pages can be viewed when browsing the wiki.

The structure page will be displayed as is, whereas the data page is displayed as the final compiled page, structure and all.

Please note that I wrote this plugin to solve a very specific problem so some of the functionality may not be generally useful.

This is also my first dokuwiki plugin and I'm not very experienced with php, so this plugin very possibly contains security issues and bugs. I really appreciate any feedback.

Declaring the structure page

All replacement commands look like the following:

~~COMMAND(x[,var]):param1[:param2[:param3]]~[!]~

Available Commands:

A sample for a list would be:

          WIKISOFTWARE = ( 'DokuWiki', '2009-12-25', 'GPL 2' ),
                         ( 'MediaWiki', '2010-04-07', 'GPL' )

Use in the template would then look like this:

          ^ Name ^ Last Release ^ License ^
          ~~LIST(0):WIKISOFTWARE:[| @0 | @1 | @2 | ]:5~~

As you can see, the first parameter (WIKISOFTWARE) names the list to display, the second one ([ @0 | @1 | @2 | ] specifies the structure of each row. The final parameter (5) is optional. If set, the table will contain at least that many rows. In the above case, 3 empty lines will be appended (5 minus the 2 lines of content). Of course the cells can contain further replacement commands:

          ~~LIST(0):SOMELIST:[| @0 | ~~IF(1):@1:YES:NO~~ | ]:5~~

Note that if the pass of these commands is less or equal to the pass of the list-command itself, they will be evaluated BEFORE the list is expanded, otherwise (like in the sample) they are expanded afterwards and will thus refer to the content of the row.

Declaring data

data is declared with simple key-value pairs, one per line: VARIABLENAME = VALUE

When declaring a variable for a LIST command, VALUE is a list of rows, where is row a is enclosed in regular brakets:

LIST = (5, true, "foo"),
       (3, false, "bar")

Please note that rows after the first need to be indented for parsing to work.

All variable declarations need to be enclosed within the following tags [VARIABLES] [ENDVARIABLES]

Maps are declared either in the structure page or a seperate data page. In the simple case they are defined like this:

NAME = a, b, c, d, e,
       f, g, h, i, j

In this case, this is a simple array, the index 0 will map to a, the index 2 to c and so on. Again, don't forget to indent rows after the first.

Alternatively, you can manually specify indices: NAME = 1 = a, 3 = b, 8 = c

This mainly makes sense if you intend to use LOOKRANGE for the lookup. There, 1 and 2 will map to “a”, 3,4,5,6 and 7 to “b” and everything else to “c”.

maps are declars within the tags [MAPS] [ENDMAPS]

Putting everything together

finally, you must put together the data. Simply put this at the end of your data page: [INCLUDE:namespace:foo:template]

When the data page is displayed, everything between [VARIABLES] and [ENDVARIABLES] is evaluated but not printed. The INCLUDE will be replaced with the content of the interpreted template page and only that will be displayed. Of course you can have multiple includes and thus construct a page from multiple templates or you can include variable definitions from a separate page.

Discussion

I need an example

Sorry, but I don't understand the intention of your plugin.
Can you please add a very simple example?
See a post with an example. — Aleksandr Selivanov 2012/10/02 15:29

Problem with old revisions

mytemplate seems to break the 'old revisions' function.

When mytemplate is enabled I cannot edit old revisions of the page, the wiki always shows the current page revision in the editor. It does not matter which revision I try to edit, the current page is edited, not the old revision I select.

When mytemplate is disabled I can edit old revisions correctly.
This worked for me: go and download the Cache and Revisions Eraser plugin and remove all the cache. — Phanboy 2013/4/25

Some observations

Great plugin, but I took me some time to get it working. Some (hopfully useful) observations I made: