Example 1: Blog Layout

A complete blog template with a base layout, article page, and sidebar partial.

Base Layout (base.tpl.php)

<!DOCTYPE html>
<html lang="<?= $this->lang ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php $this->block('title') ?>My Blog<?php $this->endblock() ?></title>
    <link rel="stylesheet" href="/css/style.css">
</head>
<body>
    <nav>
        <a href="/">Home</a>
        <a href="/blog">Blog</a>
        <a href="/about">About</a>
    </nav>

    <div class="container">
        <main>
            <?php $this->block('content') ?><?php $this->endblock() ?>
        </main>

        <aside>
            <?= $this->includeTemplate('sidebar.tpl.php') ?>
        </aside>
    </div>

    <footer>
        <p>&copy; <?= date('Y') ?> My Blog</p>
    </footer>
</body>
</html>

Article Page (article.tpl.php)

<?php $this->extends('base.tpl.php') ?>

<?php $this->block('title') ?><?= $this->postTitle ?> | My Blog<?php $this->endblock() ?>

<?php $this->block('content') ?>
    <article>
        <header>
            <h1><?= $this->postTitle ?></h1>
            <time datetime="<?= $this->postDate ?>">
                <?= date('F j, Y', strtotime($this->postDate)) ?>
            </time>
            <p class="author">By <?= $this->author ?></p>
        </header>

        <div class="content">
            <?= $this->postBody->raw() ?>
        </div>

        <section class="comments">
            <h2>Comments</h2>
            <?php if (count($this->comments) > 0) : ?>
                <?php foreach ($this->comments as $comment) : ?>
                    <div class="comment">
                        <strong><?= $comment['author'] ?></strong>
                        <p><?= $comment['text'] ?></p>
                    </div>
                <?php endforeach ?>
            <?php else : ?>
                <p>No comments yet.</p>
            <?php endif ?>
        </section>
    </article>
<?php $this->endblock() ?>

Sidebar Partial (sidebar.tpl.php)

<div class="sidebar">
    <h3>About</h3>
    <p><?= $this->blogDescription ?></p>

    <h3>Recent Posts</h3>
    <ul>
        <?php foreach ($this->recentPosts as $post) : ?>
            <li><a href="/blog/<?= $post['slug'] ?>"><?= $post['title'] ?></a></li>
        <?php endforeach ?>
    </ul>
</div>

Rendering the Article

<?php
$template = new Template('/path/to/article.tpl.php');

echo $template->render([
    'lang'            => 'en',
    'postTitle'       => 'Getting Started with Nate',
    'postDate'        => '2026-01-15',
    'author'          => 'Andy Navarro',
    'postBody'        => '<p>Nate is a great template engine...</p>',
    'blogDescription' => 'A blog about PHP and web development.',
    'recentPosts'     => [
        ['slug' => 'nate-intro', 'title' => 'Nate Introduction'],
        ['slug' => 'php-tips', 'title' => 'PHP Tips & Tricks'],
    ],
    'comments' => [
        ['author' => 'Jane', 'text' => 'Great article!'],
    ],
]);

Example 2: Admin Panel Layout

An admin interface with a sidebar menu and dashboard content area.

Admin Layout (admin.tpl.php)

<!DOCTYPE html>
<html>
<head>
    <title><?php $this->block('title') ?>Admin Panel<?php $this->endblock() ?></title>
    <link rel="stylesheet" href="/css/admin.css">
</head>
<body>
    <div class="admin-layout">
        <nav class="admin-sidebar">
            <h2>Admin</h2>
            <ul>
                <li><a href="/admin">Dashboard</a></li>
                <li><a href="/admin/users">Users</a></li>
                <li><a href="/admin/posts">Posts</a></li>
                <li><a href="/admin/settings">Settings</a></li>
            </ul>
        </nav>

        <main class="admin-content">
            <?php $this->block('admin_content') ?><?php $this->endblock() ?>
        </main>
    </div>
</body>
</html>

Dashboard Page (dashboard.tpl.php)

<?php $this->extends('admin.tpl.php') ?>

<?php $this->block('title') ?>Dashboard | Admin Panel<?php $this->endblock() ?>

<?php $this->block('admin_content') ?>
    <h1>Dashboard</h1>

    <div class="stats">
        <div class="stat-card">
            <h3>Users</h3>
            <p class="number"><?= number_format($this->userCount) ?></p>
        </div>
        <div class="stat-card">
            <h3>Posts</h3>
            <p class="number"><?= number_format($this->postCount) ?></p>
        </div>
        <div class="stat-card">
            <h3>Comments</h3>
            <p class="number"><?= number_format($this->commentCount) ?></p>
        </div>
    </div>

    <h2>Recent Activity</h2>
    <table>
        <thead>
            <tr><th>User</th><th>Action</th><th>Date</th></tr>
        </thead>
        <tbody>
            <?php foreach ($this->recentActivity as $activity) : ?>
                <?= $this->includeTemplate('admin/_activity_row.tpl.php', [
                    'activity' => $activity,
                ]) ?>
            <?php endforeach ?>
        </tbody>
    </table>
<?php $this->endblock() ?>

Example 3: Email Template

A transactional email template with a simple layout.

<!-- email_layout.tpl.php -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body style="font-family: sans-serif; padding: 20px;">
    <div style="max-width: 600px; margin: 0 auto;">
        <div style="background: #4f46e5; color: white; padding: 20px; text-align: center;">
            <h1><?= $this->siteName ?></h1>
        </div>

        <div style="padding: 20px; background: #fff;">
            <?php $this->block('email_body') ?><?php $this->endblock() ?>
        </div>

        <div style="padding: 20px; text-align: center; color: #666; font-size: 12px;">
            <p>&copy; <?= date('Y') ?> <?= $this->siteName ?></p>
        </div>
    </div>
</body>
</html>
<!-- welcome_email.tpl.php -->
<?php $this->extends('email_layout.tpl.php') ?>

<?php $this->block('email_body') ?>
    <h2>Welcome, <?= $this->username ?>!</h2>
    <p>Thanks for joining <?= $this->siteName ?>.</p>
    <p>To get started, please confirm your email address:</p>
    <p style="text-align: center;">
        <a href="<?= $this->confirmUrl ?>"
           style="display: inline-block; padding: 12px 24px; background: #4f46e5; color: white; text-decoration: none; border-radius: 4px;">
            Confirm Email
        </a>
    </p>
<?php $this->endblock() ?>

Tip: In the email example, the URL is auto-escaped by <?= $this->confirmUrl ?>, which is important for preventing XSS in HTML emails. Use raw() only when you are certain the content is safe.