Header Small Ahoy!

Template Partials

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:

So, you wanna use partials huh?

Using partials is as simple as saving a view file inside your partials directory 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) ?>

The 'partials' directory is to be found inside 'templates/views'. Strictly speaking, you do not need to store partials inside the partials directory. Simply declaring the path as 'footer' would work and would attempt to load a view file from your 'views' directory 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