Additional Includes
Every page has its own toys. A dashboard wants charts. A profile page wants an image cropper. A blog post wants syntax highlighting. With additional includes you give each page exactly what it needs – nothing more, nothing less.
From Any Controller
Just add two optional arrays to your $data:
public function dashboard(): void {
$data['page_title'] = 'Sales Dashboard';
// Things to add inside <head>
$data['additional_includes_top'][] = 'css/dashboard.css';
$data['additional_includes_top'][] = 'https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js';
// Things to add just before </body>
$data['additional_includes_btm'][] = 'js/dashboard-charts.js';
$data['additional_includes_btm'][] = 'js/realtime-updates.js';
$this->templates->admin($data);
}What Happens Behind the Scenes
The Templates module automatically turns those arrays into proper HTML:
Anything ending in .css becomes →
<link rel="stylesheet" href="...">Anything ending in .js becomes →
<script src="..."></script>Full URLs or raw HTML strings → inserted exactly as written
Here are the two lines you will find in every template file:
<?= $additional_includes_top ?? '' ?>
...
<?= $additional_includes_btm ?? '' ?>The ?? '' simply prevents errors when no extra files are declared.
Real-World Examples
Loading from a CDN
$data['additional_includes_top'][] = 'https://unpkg.com/[email protected]/dist/leaflet.css';
$data['additional_includes_btm'][] = 'https://unpkg.com/[email protected]/dist/leaflet.js';Loading assets from any module (using the module assets trigger)
$data['additional_includes_top'][] = 'gallery_module/css/lightbox.css';
$data['additional_includes_btm'][] = 'gallery_module/js/lightbox-init.js';Passing raw HTML when you need special attributes
$data['additional_includes_top'][] = '<meta name="robots" content="noindex">';
$data['additional_includes_btm'][] = '<script>console.log("Welcome!");</script>';Conditional loading
if ($product->has_gallery) {
$data['additional_includes_top'][] = 'css/lightbox.css';
$data['additional_includes_btm'][] = 'js/lightbox.js';
}Why This Rules
- Only the pages that need the assets actually load them.
- No more 2 MB of JavaScript on the login screen.
- No more unused CSS slowing down your site.
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.