Create a widget enabled template in DokuWiki

DokuWiki doesn't have native support for widget like Wordpress or any other CMS, but with some built in functions in DokuWiki, it's quite easy to create a widget-enabled template for it. The finest example is the template used by TechRecipes itself, where it has dynamic widget on the sidebar and after the wiki content.

TechRecipes widget enabled template is available for download here mohduser/tr-twitter

Define page type

Include this in template's main.php to define page type

<?php

$pagetype = 'article';

if ($INFO['namespace'] == "") { $pagetype = 'frontpage'; }
else 

if ( strpos($INFO['id'], ":start") OR strpos($INFO['id'], ":categories") ) { 
  $pagetype = 'category'; 
}

if ( $ACT !== "show" ) { $pagetype = 'special'; }

if ( $ACT === "edit" ) { $pagetype = 'edit'; }

if ( $ACT === "login" ) { $pagetype = 'login'; }

?>

Call functions accordingly

<?php

if ($pagetype == 'article') {
widget_article_share();
widget_article_info($INFO);
widget_recent_update($INFO);
widget_recent_add($INFO);
widget_articles_draft($INFO);
}

if ($pagetype == 'category') {
widget_recent_update($INFO);
widget_recent_add($INFO);
widget_articles_draft($INFO);
}

if ($pagetype == 'frontpage') {
widget_recent_update($INFO);
widget_recent_add($INFO);
widget_facebook_activity();
widget_facebook_like();
}


if ($pagetype == 'edit') {
widget_edit_info($INFO);
}

?>

Sample widget function

This will depend on your need.

<?php function widget_article_info($INFO) { ?>
<div class="widget">
<h3 class="widgettitle">Article info</h3>
        <div class="box_entry">
                <li><b>Created on:</b> <?php echo date('l jS  F Y H:i:s', $INFO['meta']['date']['created']); ?></li>
                <li><b>Last edit on :</b> <?php echo date('l jS  F Y H:i:s', $INFO['meta']['date']['modified']); ?></li>
                <li><b>Last edit summary:</b> <?php echo $INFO['sum']; ?></li>
        </div>
</div>
<?php } ?>

Sign up for Object Oriented PHP & MVC and many other great courses on Udemy to learn more.

Object Oriented PHP & MVC

Build a custom object oriented PHP MVC framework and then build an application with it!

Written by Mohd Shakir Zakaria.

Last updated on 2019-02-12.