Framework Docs Template Engine

Template Engine

Wojo uses a plain-PHP template engine. Templates are .tpl.php files — no custom syntax, no compilation step, no abstraction layer. Variables assigned in a controller become available directly in the template via the $tpl object.

Namespace: Wojo\Core\View

View API

Method Signature Description
render() render(): void Outputs header + template + footer. Called by bootstrap automatically.
snippet() snippet(string $template): void Includes a partial template by name without header/footer.
__set() __set(string $name, mixed $value): void Assigns a variable: $tpl->title = 'Hello'
__get() __get(string $name): mixed Reads an assigned variable from within a template.
has() has(string $property): bool Checks whether a variable has been assigned.

Assigning Variables

Variables set on $tpl in the controller are available by name in the template file.

PHP
// In the controller:
$tpl->pageTitle = 'My Page';
$tpl->items     = ['apple', 'banana', 'cherry'];
$tpl->template  = 'list-page';  // resolves to list-page.tpl.php
PHP
// In list-page.tpl.php:
<h1>
    <?php echo $this->pageTitle; ?>
</h1>
<ul>
    <?php foreach ($tpl->items as $item): ?>
    <li>
        <?php echo htmlspecialchars($item); ?>
    </li>
    <?php endforeach; ?>
</ul>

Template Resolution

Setting $tpl->template = 'doc' tells the view engine to include view/front/themes/master/doc.tpl.php. The file is surrounded by the theme's header.tpl.php and footer.tpl.php automatically.

Use $view->snippet('_partialName') to embed a sub-template without header/footer — for example, a sidebar or modal that is shared across pages.

Template Guard

All .tpl.php files must begin with the framework guard to prevent direct access:

PHP
<?php
   if (!defined("_WOJO")) {
      die('Direct access to this location is not allowed.');
   }
?>

The constant const _WOJO = true; is defined in index.php before the bootstrap runs. Any file accessed directly (bypassing index.php) will terminate immediately.