Skip to content

DokuWiki Template Anatomy — main.php, detail.php, CSS, and template.info.txt

DodaTech Updated 2026-06-28 7 min read

In this tutorial, you'll learn the anatomy of DokuWiki templates, including the main.php structure, detail.php for page-specific layouts, CSS organization, the template.info.txt manifest, and how templates control page rendering.

What You'll Learn

  • Template directory structure
  • The main.php file and its role
  • The detail.php file for media detail pages
  • CSS organization in templates
  • The template.info.txt manifest
  • How templates render wiki pages
  • Template inheritance basics

Why It Matters

Templates control everything your users see. The default template works, but a custom template makes your wiki look like part of your brand. Understanding template anatomy is the first step to creating a unique, professional wiki appearance. Without this knowledge, you are limited to whatever the default template provides.

Real-World Use

A company wants their internal wiki to match their brand colors and layout. Rather than using the default DokuWiki template, they create a child template that inherits from the default but overrides the header, footer, and CSS. The template.info.txt declares the parent template. The entire customization is 3 files and 50 lines of code. The wiki now matches the company website.

Learning Path

flowchart LR
  A[Plugin Security] --> B[Template Anatomy]
  B --> C[Template Variables]
  C --> D[Bootstrap Template]
  D --> E[Custom Template]
  E --> F[Template Configuration]

Template Directory Structure

Templates live in lib/tpl/. Each template has its own subdirectory:

lib/tpl/
├── dokuwiki/            # Default template (included with DokuWiki)
│   ├── template.info.txt
│   ├── main.php
│   ├── detail.php
│   ├── css/
│   │   ├── basic.less
│   │   ├── design.less
│   │   ├── links.less
│   │   └── ...
│   ├── images/
│   │   └── ...
│   ├── js/
│   │   └── ...
│   └── lang/
│       └── en/
│           └── ...
├── bootstrap3/          # Bootstrap3 template
├── minty/               # Community templates
└── mytemplate/          # Your custom template

The template.info.txt Manifest

Every template must have a template.info.txt file:

base    mytemplate
author  Your Name
email   your@email.com
date    2026-06-28
name    My Custom Template
desc    A clean, responsive template for DokuWiki
url     https://example.com/mytemplate

Template Inheritance with parent

Templates can inherit from another template:

base    mychildtemplate
author  Your Name
email   your@email.com
date    2026-06-28
name    My Child Template
desc    Child template based on dokuwiki template
url     https://example.com/mychildtemplate
parent  dokuwiki

The parent field tells DokuWiki which template to fall back to for files not present in the child template.

The main.php File

The main.php file is the primary template file. It controls the HTML structure of every wiki page.

Basic Structure

<?php
// lib/tpl/mytemplate/main.php

// Include initialization
if (!defined('DOKU_INC')) die();

// Start HTML document
?><!DOCTYPE html>
<html lang="<?php echo $lang['lang'] ?>" dir="<?php echo $lang['dir'] ?>">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php echo hsc($title) ?></title>
    <?php tpl_metaheaders() ?>
    <?php echo tpl_favicon() ?>
</head>
<body>
    <div id="dokuwiki__site">
        <div id="dokuwiki__top" class="site <?php echo tpl_classes() ?>">

            <!-- Header -->
            <header id="dokuwiki__header">
                <div class="pad">
                    <?php tpl_includeFile('header.html') ?>
                    <h1>
                        <a href="<?php echo wl('start') ?>">
                            <?php echo hsc($conf['title']) ?>
                        </a>
                    </h1>
                    <?php tpl_userinfo() ?>
                </div>
            </header>

            <!-- Main content area -->
            <main id="dokuwiki__content">
                <div class="pad">
                    <?php tpl_flush() ?>
                    <?php tpl_content() ?>
                </div>
            </main>

            <!-- Sidebar -->
            <aside id="dokuwiki__aside">
                <div class="pad">
                    <?php tpl_sidebar() ?>
                </div>
            </aside>

            <!-- Footer -->
            <footer id="dokuwiki__footer">
                <div class="pad">
                    <div class="doc">
                        <?php tpl_includeFile('footer.html') ?>
                        <?php tpl_license() ?>
                    </div>
                    <?php tpl_indexbutton() ?>
                </div>
            </footer>

        </div>
    </div>
</body>
</html>

Key Template Functions

Function Purpose
tpl_metaheaders() Outputs CSS, JS, meta tags
tpl_content() Renders the main page content
tpl_sidebar() Renders the sidebar
tpl_userinfo() Shows login info and user menu
tpl_classes() Returns CSS classes for body
tpl_includeFile() Includes optional HTML files
tpl_flush() Outputs action messages
tpl_license() Shows license information

Template Variables

Available PHP variables in templates:

  • $ID — Current page ID
  • $NS — Current namespace
  • $TITLE — Page title
  • $conf — DokuWiki configuration array
  • $lang — Language strings
  • $INFO — User and page information
  • $ACT — Current action (show, edit, etc.)

The detail.php File

The detail.php file handles the media detail page (displayed when clicking on an image or file).

<?php
if (!defined('DOKU_INC')) die();
?><!DOCTYPE html>
<html lang="<?php echo $lang['lang'] ?>" dir="<?php echo $lang['dir'] ?>">
<head>
    <meta charset="utf-8">
    <title><?php echo hsc($title) ?></title>
    <?php tpl_metaheaders() ?>
</head>
<body>
    <div id="dokuwiki__detail">
        <?php tpl_content() ?>
    </div>
</body>
</html>

This is typically simpler than main.php because it is a focused view.

CSS Organization

Templates can use CSS, LESS, or SCSS. DokuWiki compiles LESS files automatically.

CSS File Structure

lib/tpl/mytemplate/css/
├── basic.less       # Basic reset and typography
├── design.less      # Colors, backgrounds, borders
├── links.less       # Link styles
├── structure.less   # Layout, grid, positioning
├── print.less       # Print styles
└── mobile.less      # Responsive styles

User CSS Override

Users can override template CSS using conf/userstyle.css. This file is loaded after template styles:

/* conf/userstyle.css */
#dokuwiki__header {
    background-color: #f0f0f0;
}

LESS Variables

The default template uses LESS variables for easy customization:

// Default template variables
@ini_background: #fff;
@ini_text: #000;
@ini_link: #00a;
@ini_visited: #808;
@ini_site: #fff;
@ini_sidebar: #f5f5f5;
@ini_border: #ccc;

Template Functions Reference

Content Rendering

  • tpl_content() — Renders the main page content based on the current action
  • tpl_includeFile($file) — Includes an optional file from the template directory
  • tpl_sidebar() — Renders the sidebar
  • tpl_navbar() — Renders navigation toolbar

Page Structure

  • tpl_pagetitle() — Returns the page title
  • tpl_breadcrumbs() — Renders breadcrumb trail
  • tpl_youarehere() — Renders "You are here" navigation
  • tpl_actions() — Returns page action buttons (edit, history, etc.)

User Interface

  • tpl_userinfo() — Shows login information
  • tpl_searchform() — Renders the search form
  • tpl_indexbutton() — Renders the index/sitemap button
  • tpl_license() — Shows licensing information

Common Mistakes

  1. Editing main.php in the default template: Changes to the default template are overwritten on DokuWiki updates. Create a child template or custom template instead.
  2. Forgetting to call tpl_metaheaders(): Without this, CSS and JavaScript are not loaded, and the page renders without styles.
  3. Hard-coding URLs: Always use DokuWiki functions like wl() for generating wiki links instead of hard-coding URLs.
  4. Not handling mobile layout: Many custom templates only look good on desktop. Use responsive CSS to handle mobile devices.
  5. Neglecting the detail.php file: If you do not override detail.php, media detail pages may break or look inconsistent with your custom template.

Practice Questions

  1. What is the purpose of the main.php file in a DokuWiki template, and what are three key functions it typically calls?
  2. How does template inheritance work in DokuWiki, and what is the parent field in template.info.txt?
  3. What is the difference between tpl_content(), tpl_sidebar(), and tpl_breadcrumbs()?
  4. Challenge: Create a minimal custom template from scratch. The template should: inherit from the default DokuWiki template using the parent field, override the header to show a custom logo image, change the background color using CSS, add a custom footer with copyright text, and include a responsive layout. Test the template and ensure all pages render correctly.

FAQ

Can I use a template without a main.php file?

No. The main.php file is required. If it is missing, DokuWiki will not load the template. You can use inheritance to fall back to a parent template for other files, but main.php must exist in your template.

What is the difference between a template and a theme?

In DokuWiki, the terms are used interchangeably. Some other systems distinguish templates (structure) from themes (visual design). DokuWiki templates handle both structure and appearance.

How do I add Google Analytics to my template?

Add the tracking code before the closing </head> tag in main.php, or use a plugin. For template-level addition: insert the Google Analytics snippet right before <?php tpl_metaheaders() ?>.

Can templates include PHP logic?

Yes, templates are PHP files. You can include loops, conditionals, and function calls. However, keep complex logic in plugins and use templates only for presentation.

How do I update a template without losing customizations?

If you modified the template directly, your changes are lost on update. Solution: create a child template that inherits from the template you want to customize, and put all changes in the child template.

Mini Project

Goal: Analyze and document an existing template's structure.

  1. Navigate to lib/tpl/dokuwiki/ (the default template)
  2. Open template.info.txt and note its fields
  3. Open main.php and identify each section (header, content, sidebar, footer)
  4. List all tpl_*() functions used in main.php
  5. Explore the css/ directory and note which CSS files control which elements
  6. Create a diagram showing the template structure (HTML layout)
  7. Identify three elements you would customize for a specific brand

What's Next

Understanding template structure is the foundation. Now learn about template variables to access page content, user info, and navigation data in your templates.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro