The Trongate PHP Framework
Documentation
Introduction
Quick Start
Basic Concepts
Understanding Routing
Controllers
Views
Assets
Modules Calling Modules
Parent & Child Modules
Database Operations
Modules within Modules
Templates & Themes
Helpers Explained
Form Handling
Working with Files
The Module Import Wizard
Authorization & Authentication
The API Explorer
Best Practices

Help Improve Our Docs

If you’ve found an error, spotted something missing, or feel a section could be clearer or better explained, we’d love to hear from you. Your feedback helps keep the documentation accurate and useful for everyone.

Please report issues or suggest improvements on GitHub. Community input is invaluable in making the docs stronger.

Not comfortable with GitHub? No problem — you can also get in touch with us directly via our contact form. We welcome all feedback.

Creating Custom Templates

Trongate allows you to create custom HTML templates to define the structure and layout of your web pages. This guide will walk you through the process of creating your own template.

Template Location

Templates in Trongate are stored within the 'templates' module, which is located in your application's root directory. This module follows the standard Trongate module structure, containing both 'controllers' and 'views' directories.

Creating a Custom Template

Step 1: Define Your Template Name

Choose a meaningful name for your template that reflects its purpose. Template names should be in snake_case format and clearly indicate the template's intended use. Some examples of good template names include:

  • public_template
  • admin_dashboard
  • member_portal
  • auth_pages
  • sales_backend

Step 2: Create the Template Method

Open the Templates.php controller file in your templates/controllers directory and add a new method for your template:

Step 3: Create the Template View

Create a new PHP file in your templates/views directory with the same name as your template method. For example, if your method is named 'custom_template', create custom_template.php:

Key Template Components

Your template should include several important elements:

  • The base tag with BASE_URL for proper path resolution
  • Core stylesheet includes for your application
  • The Template::display($data) call where page content will be injected
  • Placeholders for additional includes ($additional_includes_top and $additional_includes_btm)

When creating a new template, ensure it's properly integrated with Trongate's core features by including the base href tag and Template::display() method. This ensures your template works seamlessly with the framework's routing and view management systems.

Using Your Template

To use your new template from any controller, specify it when calling the template method:

Always ensure your template name is unique within the Templates class to avoid conflicts with existing templates like 'admin' or 'public'.

×