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.

Additional Includes

HTML templates often need to load different JavaScript or CSS files depending on the specific page being rendered. Trongate provides a flexible system for handling these additional includes through the _build_additional_includes() method in the Templates class.

Understanding Additional Includes

Additional includes allow you to dynamically add CSS and JavaScript files to your templates. These includes can be placed either in the header (top) or footer (bottom) of your HTML document.

Basic Structure

The Templates class processes additional includes using two key variables:

  • $additional_includes_top: For files that need to be included in the document head
  • $additional_includes_btm: For files that need to be included at the bottom of the body

Implementation in Templates

Here's how to implement additional includes in your template method:

Template Usage

In your template file (e.g., admin.php), you can place the includes variables where you want the files to be loaded:

Adding Files from Controllers

To add additional files from your controllers, pass them in the $data array:

How It Works

The _build_additional_includes() method processes the files based on their extension:

  • For .js files: Generates <script src="..."></script> tags
  • For .css files: Generates <link rel="stylesheet" href="..."> tags
  • For other file types: Includes the file path as-is

The method also maintains proper HTML formatting by:

  • Adding appropriate indentation
  • Handling newlines for clean source code
  • Ensuring proper closing of HTML tags

When working with additional includes, consider the following best practices:

1. Group Your Includes Logically

Organize your includes based on their purpose and loading requirements:

2. Use Conditional Loading

Load files only when they're needed for specific functionality:

Remember to verify that all file paths are correct relative to your application's base URL. Incorrect paths may result in resources failing to load properly.

×