VulgarisOverIP

Using Multiple Templates With DokuWiki

Time for that biennial blog post, right?

Anyways, DokuWiki is a PHP based wiki that’s powerful enough to run your entire site or integrate with whatever you already have. Setting up a different look for the wiki is simple, just a matter of changing templates. But what if you want more than one look (template)?

Let me answer that question by asking another question: Why would you possibly want to two different templates for the same wiki? Well the main reason would be if you had separate administration (intranet) and public sections of your site, each with their own custom look. It would just be weird to log into your admin site, start reading a page with one theme, click a link and then view a related page in a totally different way. Not to mention that all your admin links are now gone and just as you click the back button your remember you had previously submitted a form that sent an email to all 5000 of your clients. Well, maybe they won’t even notice…

So, where do we start?

  1. Google “multiple dokuwiki templates”
  2. Check the first few links
  3. Ooh! Multitemplate plugin for Dokuwiki
  4. Hmm, last version is from 1/1/07 (that’s older than MY posts). Also won’t let us view the same page using two different templates. No good.
  5. Give up on Google, no one can code better than me!
  6. Begin randomly coding

My first attempt at a solution was a simple extension of xbr plug-in. I think it originally was supposed to convert new-lines to ’s or something crazy like that. I modified it to check the current URL and if it contained certain magic properties (“&theme=public”, for example) it would rewrite all the links on the page to also include some magic. Then I modified my one template to check for magic as well, which loaded one of two template options boot-strap style.

This solution was ugly. A waste of a good 32 minutes. At least. Also, it didn’t work. Links like “Edit this page” and “Admin” weren’t affected and it turned out that DokuWiki is so smart that it caches all the HTML it produces and then “freezes” your links after the first page visit.

Second attempt. This time, using the old noodle! Here’s the correct way to do it:

  1. Separate the original boot-strapping template into two separate templates
  2. Make a symbolic link to the /wiki directory (contains DokuWiki code) in another directory (/intranet/wiki maybe?)
  3. Modify the local.protected.conf file to check the URL for the alternate directory and then load appropriate template

Here’s an example of the only code you need:

if (isset($_SERVER['REQUEST_URI']) && strstr($_SERVER['REQUEST_URI'], '/intranet/') !== false) { $conf['template'] = 'intranet'; }

That’s it! You only need one copy of the [DokuWiki] code, one copy of the [DokuWiki] data, a symbolic link and 2-3 lines of extra code. No caching problems, no extra plug-ins and a good excuse to blog.

Comments