Compatible with DokuWiki
2010-11-07 "Anteater", 2011-05-25 "Rincewind", 2012-01-25 "Angua"
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
Search and install the plugin using the Extension Manager. Refer to Plugins on how to install plugins manually.
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.
All replacement commands look like the following:
~~COMMAND(x[,var]):param1[:param2[:param3]]~[!]~
var
is optional. If set, the result of this replacement will be stored in a variable by that name and can later be used again.x
is the “pass” during which the placeholder should be replaced. This will be 0 most of the time, but on some occasions, you may need more control over the order in which things get replaced. If you don't get the point, the list-command is a common case where using different passes makes sense and it should become obvious why.!
between the final two ~
to have MyTemplate not output anything. This makes sense if you want to calculate an intermediate result to be used later.Available Commands:
~~VAR(0):key~~
)~~LOOK(0):MAP:3~~
)~~CALC(0):round(~~VAR(0):FOO~~ * ~~VAR(0):BAR~~)~~
)~~COUNT(0):,:~~VAR(0):FOO ~~ ~~
)~~IF(0):~~VAR(0):SAYWHAT~~:what:huh~~
)~~REPLACE:Hello NAME:NAME:~~VAR(0):NAME~~ ~~
)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.
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]
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.
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
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
Great plugin, but I took me some time to get it working. Some (hopfully useful) observations I made:
~~TEMPLATE~~
(otherwise substitutions would be made in the template itself instead of the structure file). If a page has been saved once an turned into a ~~TEMPLATE~~
later, be sure to remove the corresponding path-to-dokuwiki/data/meta/
path-to-page.mytemplate
file after having added ~~TEMPLATE~~
, otherwise page editing won't work properly.[INCLUDE…
or [VARIABLES]
(this is due to the very way mytemplates works and I can't imagine an easy way to fix that)~~LISTS(…
command.~~LISTS(…
command, quotes ' ' currently have no effect. In particular, they don't prevent parens or comma from separating records or fields. — Alexander Talos-Zens 2014/03/30 09:35