Understanding Templates
This chapter provides a comprehensive guide to understanding and working with templates in the Trongate framework.
What are Templates?
In Trongate, a template is a PHP file that generates a complete HTML web page. Templates serve as the structural foundation for rendering web pages, providing a consistent layout and design across your application.
Templates vs. Views
It's important to distinguish between templates and views in Trongate:
- Templates: Encompass the entire structure of a web page, including <!DOCTYPE>, <html>, <head>, and <body> tags. They often include common elements such as headers, footers, and navigation menus.
- Views: Typically contain partial HTML content, focusing on specific components or sections of a page. Views are included within templates to populate specific content areas.
Where Templates Are Stored
Trongate organizes templates within a dedicated 'templates' directory, located in the root directory of your application.
The Templates Directory: A Special Trongate Module
While the 'templates' directory is located at the root level of your Trongate application, it functions as a full-fledged Trongate module. This unique positioning allows for global accessibility while maintaining the familiar Trongate module structure.
Throughout this documentation, you may encounter the terms 'template module' and 'template directory'. These refer to the same entity: the 'templates' folder at the root of your Trongate application.
The 'templates' module adheres to the standard Trongate module structure, comprising:
- controllers/: Houses the Templates.php controller file, which manages template loading and processing.
- views/: Contains the actual template files that define the structure of your web pages.
This structure allows you to leverage Trongate's powerful module-based architecture for managing your application's templates, while ensuring they remain easily accessible to all parts of your application.