DokuWiki Template Anatomy — main.php, detail.php, CSS, and template.info.txt
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 actiontpl_includeFile($file)— Includes an optional file from the template directorytpl_sidebar()— Renders the sidebartpl_navbar()— Renders navigation toolbar
Page Structure
tpl_pagetitle()— Returns the page titletpl_breadcrumbs()— Renders breadcrumb trailtpl_youarehere()— Renders "You are here" navigationtpl_actions()— Returns page action buttons (edit, history, etc.)
User Interface
tpl_userinfo()— Shows login informationtpl_searchform()— Renders the search formtpl_indexbutton()— Renders the index/sitemap buttontpl_license()— Shows licensing information
Common Mistakes
- 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.
- Forgetting to call tpl_metaheaders(): Without this, CSS and JavaScript are not loaded, and the page renders without styles.
- Hard-coding URLs: Always use DokuWiki functions like
wl()for generating wiki links instead of hard-coding URLs. - Not handling mobile layout: Many custom templates only look good on desktop. Use responsive CSS to handle mobile devices.
- 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
- What is the purpose of the
main.phpfile in a DokuWiki template, and what are three key functions it typically calls? - How does template inheritance work in DokuWiki, and what is the
parentfield intemplate.info.txt? - What is the difference between
tpl_content(),tpl_sidebar(), andtpl_breadcrumbs()? - Challenge: Create a minimal custom template from scratch. The template should: inherit from the default DokuWiki template using the
parentfield, 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
Mini Project
Goal: Analyze and document an existing template's structure.
- Navigate to
lib/tpl/dokuwiki/(the default template) - Open
template.info.txtand note its fields - Open
main.phpand identify each section (header, content, sidebar, footer) - List all
tpl_*()functions used in main.php - Explore the
css/directory and note which CSS files control which elements - Create a diagram showing the template structure (HTML layout)
- 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