Skip to content

DokuWiki Template Variables — Page Content, User Info, Navigation, and Language

DodaTech Updated 2026-06-28 8 min read

In this tutorial, you'll learn about the PHP variables available in DokuWiki templates, including page identifiers, configuration values, user information, navigation data, and language strings.

What You'll Learn

  • Core template variables ($ID, $NS, $TITLE)
  • Configuration variables ($conf)
  • User information ($INFO)
  • Navigation variables
  • Language and localization variables
  • Action and state variables
  • Custom template variable patterns

Why It Matters

Template variables are how you access dynamic data in your templates. Without them, every page would look identical. With them, you can show different headers for different namespaces, display user-specific information, highlight the current page in navigation, and adapt layouts based on the action being performed. Understanding template variables makes your templates intelligent.

Real-World Use

A template designer creates a navigation menu that highlights the current section. When the user is on a page in the projects: namespace, the "Projects" menu item has a different CSS class. When the user is logged in, a "Profile" link appears. When viewing the start page, a special welcome banner is shown. All of this uses template variables.

Learning Path

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

Core Page Variables

These variables are available in every template:

Variable Description Example Value
$ID Current full page ID projects:roadmap
$NS Current namespace projects
$TITLE Page title Project Roadmap
$PAGE Page template name page
$ACT Current action show, edit, preview
$DATE Current date 2026-06-28
$YEAR Current year 2026
$TIME Current time 14:30

Using Page Variables in Templates

<?php
// Add a CSS class based on namespace
echo '<body class="ns-' . str_replace(':', '-', hsc($NS)) . '">';

// Show different header on the start page
if ($ID === 'start') {
    echo '<h1 class="welcome">Welcome to our Wiki</h1>';
} else {
    echo '<h1>' . hsc($TITLE) . '</h1>';
}

// Conditional content based on action
if ($ACT === 'edit') {
    echo '<div class="edit-notice">You are editing this page.</div>';
}

Configuration Variables ($conf)

The $conf array contains all DokuWiki configuration settings:

Variable Description
$conf['title'] Wiki title
$conf['tagline'] Tagline/subtitle
$conf['lang'] Default language
$conf['template'] Active template name
$conf['useacl'] Whether ACL is enabled
$conf['breadcrumbs'] Number of breadcrumbs to show
$conf['youarehere'] Whether "You are here" is enabled

Using Configuration Variables

<?php
// Display wiki title
echo '<h1><a href="' . wl('start') . '">' . hsc($conf['title']) . '</a></h1>';

// Show tagline if configured
if (!empty($conf['tagline'])) {
    echo '<p class="tagline">' . hsc($conf['tagline']) . '</p>';
}

// Check if ACL is enabled
if ($conf['useacl']) {
    echo tpl_userinfo();
}

User Information ($INFO)

The $INFO array contains data about the current user:

Variable Description
$INFO['userinfo']['name'] User's full name
$INFO['userinfo']['mail'] User's email
$INFO['userinfo']['grps'] User's groups (array)
$INFO['client'] Client IP address
$INFO['namespace'] Current namespace
$INFO['exists'] Whether the page exists (boolean)
$INFO['rev'] Current revision timestamp
$INFO['subscribed'] Whether user is subscribed

Using User Information

<?php
// Show user-specific greeting
if ($INFO['userinfo']['name']) {
    echo 'Hello, ' . hsc($INFO['userinfo']['name']) . '!';
} else {
    echo 'Welcome, guest.';
}

// Check if page exists
if ($INFO['exists']) {
    echo '<div class="page-content">';
    tpl_content();
    echo '</div>';
} else {
    echo '<div class="page-missing">This page does not exist yet.</div>';
}

// Check user groups for admin links
if (in_array('admin', $INFO['userinfo']['grps'])) {
    echo '<a href="' . wl('admin') . '">Admin</a>';
}

Navigation data is available through template functions:

<?php
// Get breadcrumb trail
tpl_breadcrumbs();

// Get "You are here" path
tpl_youarehere();

// Get page action buttons
$actions = tpl_action('edit', true);    // true = return HTML, false = echo
$actions = tpl_get_action('edit');      // Get action data array

Action Actions

Available action names:

Action Description
edit Edit page
history View page history
backlink What links here
subscribe Subscribe to page
admin Admin panel (for admins)
profile User profile
login Login link
register Registration link
top Back to top

Building Navigation Menus

<?php
// Build namespace-based navigation
$currentNs = $NS;
$namespaces = array('projects', 'team', 'guides', 'policies');

echo '<nav><ul>';
foreach ($namespaces as $ns) {
    $active = ($currentNs === $ns) ? ' class="active"' : '';
    echo '<li' . $active . '>';
    echo '<a href="' . wl($ns . ':start') . '">' . hsc($ns) . '</a>';
    echo '</li>';
}
echo '</ul></nav>';

Language Variables

The $lang array contains localized strings:

<?php
// Display localized "Edit" button text
echo tpl_action('edit');

// Or use language strings directly
echo $lang['btn_edit'];      // "Edit this page"
echo $lang['btn_create'];    // "Create this page"
echo $lang['btn_history'];   // "Old revisions"
echo $lang['btn_search'];    // "Search"
echo $lang['loggedinas'];    // "Logged in as"

Available language variable prefixes:

Prefix Area
btn_ Button labels
search_ Search-related text
edit_ Editing-related text
show_ Display labels
acl_ ACL-related text
msg_ Messages and notifications

Template Path Variables

<?php
// Get template directory URL
echo tpl_basedir();         // Directory path
echo tpl_url();             // URL path

// Example: include template-specific resources
echo '<link rel="stylesheet" href="' . tpl_url() . '/css/custom.css">';

Global Variables

<?php
// Global variables available in templates
global $ID;           // Same as $ID
global $conf;         // Same as $conf
global $lang;         // Language array
global $INFO;         // User info
global $JSINFO;       // JavaScript info (passed to JS)
global $ACT;          // Current action
global $QUERY;        // Search query (on search pages)
global $auth;         // Authentication object

Common Variable Patterns

Namespace-Specific Styling

<?php
// Add CSS class based on namespace depth
$nsDepth = count(explode(':', $NS));
echo '<div class="ns-depth-' . $nsDepth . '">';

Page Type Detection

<?php
// Detect page type
$isMediaDetail = ($ACT === 'media');
$isSearch = ($ACT === 'search');
$isAdmin = ($ACT === 'admin' || $ACT === 'login');

if ($isAdmin) {
    // Render admin layout
} elseif ($isSearch) {
    // Render search layout
}

User Status Indicators

<?php
// Show editing controls only for users who can edit
if (auth_quickaclcheck($ID) >= AUTH_EDIT) {
    echo '<div class="edit-tools">';
    tpl_action('edit');
    tpl_action('history');
    echo '</div>';
}

Common Mistakes

  1. Assuming $INFO['userinfo'] is always set: For anonymous users, $INFO['userinfo'] may be empty. Always check with if ($INFO['userinfo']['name']) or if ($_SERVER['REMOTE_USER']).
  2. Not escaping variables in HTML: Always use hsc() when outputting variables in HTML content to prevent XSS.
  3. Hard-coding action names: Use tpl_action() instead of hard-coding button HTML. It handles ACL checks, language, and permissions automatically.
  4. Overriding $conf values: The $conf array is read-only in templates. You cannot change configuration from a template.
  5. Using echo tpl_content() instead of tpl_content(): Functions like tpl_content() echo output directly. They do not return a value to echo.

Practice Questions

  1. What is the value of $ID when viewing a page at http://yourserver/wiki/projects:roadmap?
  2. How would you create a template that shows a different header image for each namespace?
  3. What template variable or function would you use to check if the current user is an admin?
  4. Challenge: Create a template snippet that displays a personalized dashboard on the start page. The dashboard should: greet the user by name (or show "Guest" if not logged in), list the 5 most recently modified pages (using tpl_recents() or similar), show a link to the user's profile, display different content based on whether the user is in the "admin" group, and highlight the current namespace in the navigation menu.

FAQ

What is the difference between $ID and $NS?

$ID is the full page ID including namespace (e.g., projects:roadmap). $NS is just the namespace portion (e.g., projects). For root namespace pages, $NS is empty.

Can I access $_GET and $_POST in templates?

Yes, templates are PHP files. However, to follow security best practices, use DokuWiki's $INPUT object instead of directly accessing superglobals: $INPUT->get->str('param').

How do I check if the current user is logged in?

Check $_SERVER['REMOTE_USER'] or $INFO['userinfo']['name']. Both are empty for anonymous users and contain the username for logged-in users.

Can I use template variables in CSS?

You cannot directly use PHP variables in .css files. Use inline styles in main.php or create a PHP file that outputs dynamic CSS: echo '<style>body { background: ' . $conf['bg_color'] . '; }</style>' in the head section.

How do I get the current page's modification date?

Use @mod in the page content or $INFO['lastmod'] in template code to get the last modification timestamp. Format it with PHP's date() function.

Mini Project

Goal: Create a template that uses variables for intelligent rendering.

  1. Create a child template (or modify a copy of the default template)
  2. Add a namespace-based color scheme: pages in projects: namespace get a blue header, pages in guides: get green, all others get default
  3. Add a user greeting in the header showing the user's full name
  4. Show a "You are here" breadcrumb trail below the header
  5. Add a conditional section: if the page does not exist, show a custom message instead of the default "Create this page" link
  6. Add admin-only links (admin panel, user manager) that only appear for admin users
  7. Test with different users and namespaces

What's Next

Template variables make templates dynamic. Now explore the Bootstrap template for responsive, modern wiki designs.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro