DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:templater

Templater Plugin

Compatible with DokuWiki

  • 2022-07-31 "Igor" yes
  • 2020-07-29 "Hogfather" unknown
  • 2018-04-22 "Greebo" unknown
  • 2017-02-19 "Frusterick Manners" unknown

plugin Allows dokuwiki pages to be used as templates to be inserted into other dokuwiki pages, such as Wikipedia.

Last updated on
2023-01-03
Provides
Syntax
Repository
Source

Warning

This plugin is experimental, and its behavior subject to change in the future. It may also be folded into the include plugin

Description

The Templater plugin is an extension of and older version of include plugin. Like the include plugin, it allows you to embed one wikipage inside of another. Unlike the include plugin, the Templater also allows you to pass the included wikipage substitution strings to change the output of the included wikipage (also called infobox on MediaWiki).

Just like the include plugin you use it like this:

{{template>pagename}}

You may as well include pages from a different namespace: {{template>namespace:pagename}}. The namespaces shortcuts do also work: {{template>:pagename}} (top namespace) or {{template>.namespace:pagename}} (subnamespace).

Optionally you can limit the included page to a specific section (including its subsections):

{{template>pagename#sectionname}}

Template with string substitutions

The real power of this plugin comes in to play when you want to use the same general layout for an element inside of a wikipage, but with different pieces of data. You create a new template page, and instead of putting in the actual values, you give each value a name, and enclose them in at-signs like this:

=== This is the wikipage 'TemplateWikiPage' ===
== @subtitle@ ==
My name is @name@. I am a @value@.

Then on a page where you want to include this template, but with string substitutions, you would do this:

{{template>TemplateWikiPage|subtitle=Foo|name=Jonnay|value=Crazy Guy}}

Which outputs this:


This is the wikipage 'TemplateWikiPage'

Foo

My name is Jonnay. I am a Crazy Guy.


Template's sections

When including only a specific section, the specified heading will not be printed, only the subheadings will be (lower level). And when the plugin finds a header at the same level as the specified heading, it stops printing.

For example, in this page, i want to include section My section:

====== Page title here ======
Some introductory text for template page.
=== My section ===
First text here.
== @subtitle@ ==
My name is @name@. I am a @value@.
=== Another template ===
Text for second section template.

When you call:

{{template>pagename#My section |subtitle=Foo |name=Jonnay |value=Crazy Guy}}

Will output this:


First text here.

Foo

My name is Jonnay. I am a Crazy Guy.


In other words: :!: no headings are printed, just subheadings!

Escape Sequence

There are just one for now.

Character Escape sequence
| \|

Installation

To install, you can use the URL given above.

For more details, read plugin installation instructions.

Style

The included page is set into a <div> tag of class templater.

.templater {
    padding: 0.5em;
}

Changes

  • 2023-01-03 v0.6.1
    • By trimming off quotation marks after the whitespace trim, we allow users to wrap their strings in quotation marks in order to keep any intentional leading or trailing whitespace - useful for bulleted lists, code blocks etc. (by Turq Whiteside)
  • 2022-11-27 v0.6
    • Fixed doesn't show the heading when calling just a section
    • Complete rework of function _getSection()
  • 2022-11-25a v0.5.2
    • Better fix for {{template>page#section}} doesn't exist: added error message
    • Updated error messages to look better
    • Updated english and brazilian portuguese translations
  • 2022-11-25 v0.5.1
    • Internationalization: added lang/en and lang/pt-br
    • Bug fix for when {{template>page#section}} doesn't exist
  • 2022-11-24 v0.5
    • Fixed some warnings
    • Doesn't show the heading when calling just a section of a template {{template>page#section}}
  • 2022-11-21 v0.4
    • Updated v0.3.1 to work with 2022-07-31 Igor:
      • Updated functions handle (line 91) and render (line 117)
      • Fixed array_search() warning (line 152) by Jack126Guy
      • Fixed PHP 7+ error (line 171)
      • Fixed PHP curly braces (line 229)
    • Daniel Dias Rodrigues' first update

For a complete changelog.

To Do

  • Better error handling in _massageReplacers
  • Make templated (generated) pages indexable using idx_addPage() for fulltext search and backlink lookup using ft_backlinks()
  • Template caching of parser instructions.
  • Make the code a little clearer
  • Use > in template arguments to point to a wikipage containing a dataset.
  • Default template namespace.

Discussion

House cleaning
I'm deleting the “outgrown” discussions about bugs and new features that have already been fixed or included in past versions.
Daniel D. Rodrigues 2022-11-23 17:58 (UTC)

Use with inline folding plugin

This text copied wholesale from the include plugin. It should work the same.

Use the block type of the folded text plugin, if you want to have another page available but hidden until the user clicks the inline folding icon. The syntax would be such as:

++++folder link title| {{templater>page to include}} ++++

Suggestions, Questions, Commentary

Just a question - how is this plugin actually different from the older included plugin? Is there any reason to have both installed?

It's not. It is built upon the older include plugin, but allows you to do text substitution with the included wikipage. Jonathan Arkell 2005-10-25 19:43

Dynamic Templating?

Great plugin! Is there a way to have it handle simple logic within the template itself? (Major Edit - I know know how to ask the question) - is there any way to include parser functions in a template?


Data entry and handling suggestions.

I very much needed this plugin, thanks. I think the data entry needs to be handled much easier than it currently is. Maybe something similar to the template plugin datafiles which uses a normal DokuWiki list of name:value pairs and is much easier to write. The template plugin allows the data to be culled from a data page or inline in the arguments. Also the template plugin data files support multiple records in one file, if would be very nice to see a module mode where it can loop the data set through the template for each one or for a specific field match. Oh that would also allow for entry of more markup that cant be normally added in {}.

— ShawnA


[FEATURE REQUEST] Make generated content indexable using idx_addPage()

Please make generated content of templated pages indexable using idx_addPage() for fulltext search and backlink lookup using ft_backlinks().

I think it would be very usefull!


Include pictures in the page using a template

It would be nice to be able to include pictures in the page using a template. This seems to be a problem as they use {{<link>}}. A possible way to fix this would be using some kind of replacement for this (e.g. <pic>...</pic> or whatsoever). At the moment, my 'workaround' is using {{@picname@}} in the template, however the little “picture-button” adds a link with {{ and }}, so you have to modify it yourself.

— Anonym

Further Bugs / Feature Requests

Need escaping for = character. Fixed by adding the limit parameter (which is set to 2) to explode() calls.

Fixed since v0.3.1 2009-03-21
Daniel D. Rodrigues 2022-11-23 21:09

Another problem is, it's not possible to include image tags for values, since both image and template tags end with }}.

Same issue as :!: Include pictures in the page using a template, that's why both issues were grouped together under same title. Not implemented yet.
Daniel D. Rodrigues 2022-11-23 21:09

salviati 2008-06-20


Use template inline?

Hi. Great job with this plugin. One question:

Is there a way to use this plugin so that the included element can be placed inline? That is, not generating a new paragraph for every template. I'm asking because I'm trying to use this to templatize contents inside a list, with no good effect. Even though the syntax is correct and neither DokuWiki or validators do complain, the effect of using {{templater>something}} inside a list is that the included element is placed in a new paragraph, resulting in unwanted line breaks and empty paragraphs. The same happens if the plugin is used inside a normal paragraph.

I already tried using a CSS to force the div element as display: inline, as well as changing the <div> to a <span>, but the DokuWiki software responds by inserting unwanted paragraph terminators before the plugin output, something like:

...some text
</p>
<div class="templater">...
</div>
some more text

That would be my request: inline usage for templates. Thanks.

Ryan Chappelle 2008/12/01 05:37


Problem with ODT plugin

Hello fine plugin, but, it appears to have a problem to export the page with ODT plugin. Page exported are empty.

Bruno Teuile 2010/04/14 12:30

This issue is still true — Daniel D. Rodrigues 2022-11-29 16:45 (UTC)

Dokucms template breaks #section is included

If I don't include the section, it seems to work fine. But when I include the section:

  1. I have my “Edit” buttons near the top of my sections, this plugin pushes those bottons to the bottom of the section.
  2. If I use the top section, it will include all the sub-sections below that.

Ability to include leading whitespace

This has been resolved; if you want to include leading whitespace, wrap your string in quotation marks.

If I have whitespace at the beginning of the variable, it gets cut off. This is useful in many cases but causes problems in others - for instance, if I'm trying to put a bulleted list into one section of an infobox. There should be an escape character or something to force all following whitespace to be included.

Turq Whiteside

I imagine this the Pull Request #01. Thank you. — Daniel D. Rodrigues 2023-01-03 18:54 UTC
Yup! realized after I made this post that I could make this particular change myself even with my limited PHP knowledge. Hope it helps others as well.

Turq Whiteside


Footnotes

Currently, footnotes are rendered at the end of the template rather than the end of the page. For some use cases this is fine, but for things like infoboxes, it breaks the entire formatting of the page, with only moderate workarounds available.

Thanks for adopting this plugin!

Turq Whiteside

plugin/templater.txt · Last modified: 2023-01-13 21:22 by Turq

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