You are here: start » en » Internal Documentation » DokuWiki extensions (WvdS) » Snippet » Quickstart: create a snippet and place it

Quickstart: create a snippet and place it

The shortest way from “the plugin is installed” to “the same HTML block sits on two pages and is maintained in one place”. Three steps, about five minutes.

Prerequisites

  • wksnippet is installed and enabled in the Extension Manager.
  • You are signed in as superuser — the editing screen is administrators only.
  • The wiki's save directory is writable. The snippet is stored as a file under <savedir>/wksnippet/, not in the plugin folder, which is why it survives every reinstall of the plugin.

Step 1: open the screen

Admin → WvdS Snippets, directly /doku.php?do=admin&page=wksnippet.

Step 2: create the snippet

Add a new entry. It needs two things.

Key — letters, digits, underscore and hyphen:

contact_box

Content:

<div class="contact-box">
  <h3>Contact</h3>
  <p>info@example.com</p>
</div>

Saving writes the file <savedir>/wksnippet/contact_box.html.

Step 3: place it on a page

Edit any wiki page and write:

{{wk:snippet>contact_box}}

Check the result

The box is on the page — and it is there regardless of whether DokuWiki's own htmlok setting is on. That is the point: HTML from a managed file instead of HTML in page text.

Two counter-checks:

  • Put the same line on a second page, change the snippet on the screen and reload both. Both changed.
  • Write {{wk:snippet>no_such_key}} on a page. The page still renders; the HTML source carries a comment naming the missing key. A wrong key breaks nothing and vanishes without trace either.

Next step

  • wki18n — if the snippet should show different text per language.
  • wksnippet (German) — the package page: every form of the markup, the helper for calling from your own code, and why allowPhp needs two independent switches.
en/wiki/dwe/wksnippet/quickstart.txt · Last modified: by 0.0.0.0