Dokuwiki - Render Plugin

1 - About

If you want to add content without adding a tag in your page, you need to create your own render engine.

2 - Prerequisites

You need to have basic knowledge of the dokuwiki parser

3 - Variable

Plugin Name: myrender

4 - Steps

  • Create a render plugin with the Wizard plugin
  • Example of a plugin info file (in lib/plugins/myrender/)
base   myrender
author Nicolas GERARD
email  gerardnico's mail @gmail.com
date   2015-04-02
name   Render Plugin of Gerardnico.com
desc   Render plugin that add generated content after the first section of the second level of headings
url    https://www.dokuwiki.org/plugin:nicorender

The name of your class must be renderer_plugin_“Name of my Render Plugin”, renderer_plugin_“Value of base in plugin info file” (ie renderer_plugin_myrender)

  • Add the canRender() method to the render class in order to list the plugin in the options for config:renderer_xhtml setting in its Configuration Manager.
public function canRender($format) {
    return ($format=='xhtml');
}
  • Add the getFormat function
function getFormat() {
        return 'xhtml';
}

5 - Example

<?php
 
if(!defined('DOKU_INC')) die('meh.');
 
 
require_once DOKU_INC.'inc/parser/xhtml.php';
 
/**
 * DokuWiki Plugin nicorender (Renderer Component)
 *
 * The Nico XHTML Renderer
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Nicolas GERARD <gerardnico at the gmail.com>
 *
 * This is a replacement render of the DokuWiki's main renderer
 * That format the content that's output the tpl_content function.
 */
class  renderer_plugin_nicorender extends Doku_Renderer_xhtml
{
 
    function getFormat() {
        return 'xhtml';
    }
 
    /*
     * Function that enable to list the plugin in the options for config:renderer_xhtml
     * http://www.dokuwiki.org/config:renderer_xhtml
     * setting in its Configuration Manager.
     */
    public function canRender($format)
    {
        return ($format == 'xhtml');
    }
 
 
    /**
     * Modify the render of an heading
     *
     * @param string $text the text to display
     * @param int $level header level
     * @param int $pos byte position in the original source
     */
    function header($text, $level, $pos)
    {
        // Add the level and position information
        $this->doc .= '<p>Header Level: ' . $level . ', Position ' . $pos. '</p>;
 
        // Call the parent function (ie xhtml.php:header)
        parent::header($text, $level, $pos);
 
    }
 
 
}

6 - Documentation / Reference

  • Bookmark "Dokuwiki - Render Plugin" at del.icio.us
  • Bookmark "Dokuwiki - Render Plugin" at Digg
  • Bookmark "Dokuwiki - Render Plugin" at Ask
  • Bookmark "Dokuwiki - Render Plugin" at Google
  • Bookmark "Dokuwiki - Render Plugin" at StumbleUpon
  • Bookmark "Dokuwiki - Render Plugin" at Technorati
  • Bookmark "Dokuwiki - Render Plugin" at Live Bookmarks
  • Bookmark "Dokuwiki - Render Plugin" at Yahoo! Myweb
  • Bookmark "Dokuwiki - Render Plugin" at Facebook
  • Bookmark "Dokuwiki - Render Plugin" at Yahoo! Bookmarks
  • Bookmark "Dokuwiki - Render Plugin" at Twitter
  • Bookmark "Dokuwiki - Render Plugin" at myAOL
dokuwiki/render.txt · Last modified: 2015/04/08 22:01 by gerardnico