Trongate PHP Framework Docs
Introduction
Quick Start
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Form Validation
Working With Files
Image Manipulation
Working With Dates & Times
Language Control
Security
Tips And Best Practices

Custom 404 Pages

Trongate has always made 404 pages dead simple. In v2 it's even cleaner.

The Single Source of Truth

Open this file →

config/config.php

And you'll find this line →

PHP
define('ERROR_404', 'templates/error_404');

When a URL cannot be matched, Trongate automatically calls →

PHP
$this->templates->error_404();

The above code simply loads this view →

modules/templates/views/error_404.php

It uses the exact same mechanism as admin() and public().


Three Ways to Customize Your 404 Pages

Option 1 – Quick & Easy (most common)

Just edit the existing file →

modules/templates/views/error_404.php

Make it friendly, funny, or brutally honest – your call.

Option 2 – Use a Different View in the templates Module

Add a new method to this file →

modules/templates/Templates.php
PHP
public function my_cool_404(array $data = []): void {
    $this->display('my_cool_404', $data);
}

Create this view →

modules/templates/views/my_cool_404.php

Then change the constant →

PHP
define('ERROR_404', 'templates/my_cool_404');

Option 3 – Point to Any Module/Method You Like

Want a completely custom 404 page with extra logic? Point the constant anywhere →

PHP
define('ERROR_404', 'errors/not_found');
// or
define('ERROR_404', 'welcome/oops');
// or even
define('ERROR_404', 'modern_templates/minimal');

Trongate will automatically call that module and method.

Real-World Example (Simple & Clean)

Here's a tidy, beginner-friendly custom 404 that still feels professional →

PHP
// config/config.php
define('ERROR_404', 'errors/show_404');

Then, from within modules/errors/Errors.php:

PHP
<?php
class Errors extends Trongate {
    public function show_404(array $data = []): void {
        $data['page_title'] = 'Page Not Found';
        $data['message']    = 'Sorry, we couldn\'t find that page.';
        $this->templates->public($data);
    }
}

You can, of course, make it as fancy as you like later – add logging, suggested pages, a search box – but the pattern is always the same: one constant, one method, one template.

One line in config.php → total control over every 404.

No hooks, no events, no middleware. Just Native PHP doing what it does best.

Congratulations! You now know everything there is to know about templates in Trongate v2.

Go build something beautiful.

We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.

Share your thoughts in the Documentation Feedback.

Leave Feedback About This Page