PureWiki utilizes a straightforward, PHP-based templating system for rendering the public frontend. This system prioritizes simplicity and performance over complex template languages like Twig or Blade.

Architecture

Themes are located in the themes/ directory. The core layout file is always named page.php.

Directory Structure

themes/default/
├── page.php          # Main layout file
├── other-layout.php  # Optional: further layouts, selectable per page
├── system/           # Templates used by PureWiki itself
│   └── search.php
├── elements/         # Reusable HTML snippets
│   ├── header.php
│   ├── content.php
│   ├── footer.php
│   └── search_result.php
├── style.css         # Stylesheet
├── script.js         # Theme script
└── theme.json        # Optional: adjustable theme colors
Performance Tip:
When including static snippets like header.php, use echo file_get_contents(__DIR__ . '/path') to minimize PHP parsing overhead.

Placeholders and Variables

Placeholders are denoted by {{ variable_name }}. The renderer replaces these during the build process.

Available System Variables

Conditional Logic

The renderer supports simple {{ if variable }} and {{ endif }} blocks.

{{ if show_left_sidebar }}
  <aside>
    {{ virtual:left_sidebar }}
  </aside>
{{ endif }}

Virtual Pages and Macros

Themes rely on Virtual Pages ({{ virtual:name }}) for global content and Macros ({{ macro:name }}) for dynamic logic like search or navigation.

PHP Variables

Templates are PHP files, so they can also use these variables directly. Other variables of the renderer are not available. Values are not escaped, so use htmlspecialchars() for output.

Layout Templates

Besides page.php, a theme can contain more layout files. The Layout Template setting of a page selects the file by name, see Page Settings. If the file does not exist, page.php is used.

System Templates

Templates in the system/ folder are used by PureWiki itself and do not show up as layout templates in the Page Settings. system/search.php is the layout of the search page and places the form with {{ macro:search_page }}. If a theme has no system/search.php, the search page uses page.php and shows the form as {{ content }}.

Search Result Template

elements/search_result.php defines the markup of one search result. It is plain HTML without placeholders. Elements with a data-pw-field attribute are filled for every result, missing fields are skipped and empty fields get the hidden attribute. Without this file a basic card is used.

<article class="pw-search-card">
    <a class="pw-search-card-title" data-pw-field="title"></a>
    <p class="pw-search-card-tags" data-pw-field="tags"></p>
    <p class="pw-search-card-excerpt" data-pw-field="excerpt"></p>
    <time class="pw-search-card-date" data-pw-field="date"></time>
</article>

Theme Colors

A theme can offer colors that administrators change under Global Settings > Appearance > Theme Colors, separately for light and dark mode. The colors are declared in theme.json:

{
    "colors": {
        "--pw-primary": {
            "label": "settings.theme_color_primary",
            "light": "#0172ad",
            "dark": "#3fa9dd"
        }
    }
}

For every color that differs from its default, PureWiki adds an override to the head, for example :root{--pw-primary:light-dark(#ff0000,#ff4242)}. The stylesheet therefore has to use the variable and set color-scheme so light-dark() works. A theme without theme.json has no adjustable colors.

Default Theme

The default theme is written in plain CSS without a framework. It reads its design from CSS variables in :root. The adjustable base colors are the source for derived colors, which follow automatically when a color changes.

Variable Description
--pw-primary Accent color for buttons, link hover, focus and active states. Adjustable.
--pw-bg / --pw-fg Background and text color. Adjustable.
--pw-surface, --pw-border, --pw-muted Derived from background and text.
--pw-color-info, -success, -warning, -important Status colors for callouts and messages.
--pw-radius, --pw-spacing, --pw-container-width, --pw-header-height Shape and layout.
--pw-font-sans, --pw-font-mono Font stacks.

Light and dark mode use light-dark(). Without a choice, the theme follows the system setting. The toggle in the header sets data-theme="light" or data-theme="dark" on the <html> element and stores the choice in the browser. Custom CSS and landing pages can use the same variables.

Minified files:
The default theme loads style.min.css and script.min.js. There is no build step. After editing style.css or script.js, create the minified files with a minifier of your choice.
Previous default theme:
The former PicoCSS-based theme is still available as default_picocss and can be selected under Global Settings > Appearance.