DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:wst

“Wikimedia Style Templates” Plugin

Compatible with DokuWiki

  • 2024-02-06 "Kaos" unknown
  • 2023-04-04 "Jack Jackrum" yes
  • 2022-07-31 "Igor" yes
  • 2020-07-29 "Hogfather" yes

plugin Wikimedia-style templates

Last updated on
2018-07-22
Provides
Syntax
Repository
Source

This plugin provides a syntax for WikiMedia-style templates.

Installation

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

If you install this plugin manually, make sure it is installed in lib/plugins/wst. It might not work if the directory is called differently.

Examples/Usage

Let's assume that we need to add the same fragment to many articles, something like “The main article for this section is [link]”. In order to automate this task, we'll create a template that would accept the link destination and generate the desired text with proper formatting.

Let's also assume that the default namespace for our templates is set to “template” (you can check your settings in “Admin→Configuration Settings”).

Minimal example

First, we create a new page called “template:main” with the following contents:

template:main
//The main article for this section is **[[:{{{1}}}|{{{1}}}]]**.//

Now go to the desired article and insert the following code:

{{wst>main|Article_name}}

where “Article_name” is the page that your link will point to. After you save it, you will get:

The main article for this section is Article_name.

Includeonly tag

The template in the minimal example works fine, but our “template:main” page looks ugly:

The main article for this section is {{{1}}}.

Let's change the template so that the desired text appears on other pages (where the template code {{wst>main|}} is inserted), but is hidden from the template page itself. We will wrap the code between <includeonly> and </includeonly> tags, as follows:

template:main
<includeonly>//The main article for this section is **[[:{{{1}}}|{{{1}}}]]**.//</includeonly>

Now the template page looks empty, although it contains the template code.

Noinclude tag

Instead of showing the ugly template code (and instead of showing an empty page), let's add some text that would appear on the template page, but not on pages where the code {{wst>main|}} is inserted. We will wrap this text between <noinclude> and </noinclude> tags, as follows:

template:main
<noinclude>Plugin syntax: {{wst>main|Article_name}}</noinlcude>
 
<includeonly>//The main article for this section is **[[:{{{1}}}|{{{1}}}]]**.//</includeonly>

Template complete with documentation

When creating a template, it would be nice to also create a documentation for the users. One way to create documentation is to create another template, say “main_doc” or “main/doc”. The documentation template will only show the template syntax and the resulting text.

template:main_doc
====== Documentation: main ======
 
<noinclude><< [[template:main|Main]]</noinclude>
 
===== Syntax =====
 
<nowiki>{{wst>main|Article_name}}</nowiki>
 
===== Output =====
 
//Main article for this section is **[[category:article|Article_name]]**.//
template:main
<noinclude>{{wst>main_doc}}</noinclude>
 
<includeonly>//The main article for this section is **[[:{{{1}}}|{{{1}}}]]**.//</includeonly>

Syntax

A basic syntax for templates created with WST plugin is:

{{wst>template_name|argument_1|argument_2}}

where:

  • the template code is always wrapped between double curled brackets;
  • wst> is common for all templates;
  • template_name is the name of a page in wst namespace (default is “template:”);
  • argument_1, argument_2 etc. are arguments to the template code separated by a vertical line.

Named and numbered parameters

By default, each argument can be referred by its ordinal number, i.e. {{{1}}} refers to the first argument, {{{2}}} to the second etc. It is possible to explicitly specify the number of the argument:

{{wst>template_name|1 = argument_1|2 = argument_2}}

In this notation, the actual order of arguments does not matter any more.

Besides this, arguments can be referred to by a name. For example, in the following code

{{wst>template_name|a = argument}}

the parameter can be referred to by {{{a}}}.

Tags

  • <noinclude>...</noinclude> – the text will be displayed on a page (e.g. a template page), but will not be shown on pages that call the template.
  • <includeonly>...</includeonly> – the text will be displayed only on pages that call a template, but not on a template page itself.

Configuration and Settings

The only setting available is “Default namespace for Wikimedia-style templates”, which defaults to “template”. Leaving the default value should be OK for most installations. If this namespace is already used by another template, just provide another value.

Development

Change Log

  • 2017-04-17
    • Initial release

Known Bugs and Issues

ToDo/Wish List

[developers roadmap]

FAQ

Discussion

Does this only work for links. What if the user has a paragraph marked for H1 and wants to change it to H2? What would the template look like? Or am I misunderstanding how this works?

This plugin is not supporting backlinks, so there is no way to use dokuwiki backlinks functionality for links in templates. Also because of that there is no way of knowing which pages include template page.
lopar4ever [at] gmail

It's worth mentioning in the discussion that this isn't always an undesirable feature, for instance when creating inter page link lists etc that would muddle the meaning of a page-link by adding links all over the place.

Also, you can find the usage of a template with the search engine. It will hit “{{wst>…” just like any other text on the pages. I also suspect plugins like the PageQuery plugin might be able to do that programmatically.

Localization, GitHub, Enhancement

I am the current maintainer of Templater. WST is everything I wanted. If I had found it earlier, I wouldn't have adopted the Templater. I'm amazed that after 5, almost 6, years it still works without the need for a patch. Yes, tested in Jack Jackrum today, right now.

Could the developer:

  1. Add this plugin to https://translate.dokuwiki.org for easier translation? If not possible, could developer add my translation to source? Download here pt-br (Google Drive).
  2. Move this to GitHub instead of BitBucket?
  3. In plugin.info.txt, is better to change url to https://www.dokuwiki.org/plugin:wst instead of https://bitbucket.org/vitalie_ciubotaru/wst. All plugins do this way.

Daniel D. Rodrigues 2023-12-08 20:29

ParserFunctions

Please, try my ParserFunctions plugin, it's a perfect companion for WST and Templater.

Daniel D. Rodrigues 2023-12-10 21:13

Conflict between the move plugin and the wiki style template plugin

I reported a bug when the move plugin scrambles variable inserts in WST-templates, but reading through the page for the move plugin it seems the WST plugin might need to implement some management for moves and move events.

I'm reporting this here because there doesn't seem to be any other place?

plugin/wst.txt · Last modified: 2024-03-20 18:18 by 193.138.218.203

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