Trongate Docs
switch to dark modeswitch to dark mode
Template Partials

Template Partials

Just To Let You Know
What you're about to read here is entirely optional.  It's perfectly acceptable to not use partials inside your templates.

What Are Partials?

Some developers like to break their page templates up into partials (sometimes referred to as 'components').  A partial is a section of code that is usually associated with a particular section or function, within a greater page template.  Examples of partials could be:

  • a header
  • a footer
  • a login area
  • a top navigation bar

So, you wanna use partials huh?

Using partials is as simple as saving a view file inside your partials folder and using Trongate's in-built 'Partial' method to load your partial.  For example,

​<?= Template::partial('partials/footer') ?>​

As you would expect, partials can receive, display and manipulate data that has been passed in from your calling module.  This can be easily achieved by passing in a $data array as an argument.  For example,

​​<?= Template::partial('partials/footer', $data) ?>​

Just To Let You Know
The 'partials' directory is to be found inside 'templates/views'.  Strictly speaking, you do not need to store partials inside the partials folder.  Simply declaring the path as 'footer' would work and would attempt to load a view file from your 'views' folder within your 'template' module.

Below is an example of a template that does not use any partials:

no partials to be found here

Here's the same template but with the footer now being called as a partial:

this template will attempt to load a partial called footer.php


If you have a question or a comment relating to anything you've see here, please goto the Help Bar.