public()
public function public(array $data): void
Description
Displays the public theme template with provided data. This method loads a clean, public-facing layout designed for websites and landing pages. It processes additional CSS/JavaScript includes before rendering the template. The method automatically injects your view content into the public layout using the display() helper. Unlike the admin template, the public template provides a minimal structure, giving you maximum flexibility for front-end design.
Parameters
| Parameter | Type | Description | Default | Required |
|---|---|---|---|---|
| data | array | An associative array containing the data to pass to the template view. Common keys include 'page_title', 'view_module', 'view_file', 'additional_includes_top', and 'additional_includes_btm'. | N/A | Yes |
Return Value
| Type | Description |
|---|---|
| void | This method does not return a value. It outputs the complete HTML page directly. |
Additional Includes
The public() method automatically processes two special array keys in the $data array: additional_includes_top and additional_includes_btm. These allow you to inject additional CSS files, JavaScript files, or raw HTML into specific locations within the template.
How It Works
- additional_includes_top - Files or HTML added to this array are inserted inside the
<head>section of the page - additional_includes_btm - Files or HTML added to this array are inserted just before the closing
</body>tag
The method automatically detects file types and generates the appropriate HTML:
- Files ending in
.cssare wrapped in<link rel="stylesheet" href="...">tags - Files ending in
.jsare wrapped in<script src="..."></script>tags - Full URLs and raw HTML strings are inserted exactly as provided
Example #1
The code sample below demonstrates the simplest usage - loading the public template with just a page title. The view file would be automatically determined by the method name.
Example #2
This example explicitly specifies which view file to load and which module it belongs to, providing clear documentation of the template structure.
Example #3
This example shows how to pass database records to the view for rendering dynamic content on a public page.
Example #4
This example demonstrates how to add external CSS frameworks and libraries that are specific to a particular page.
Example #5
This example shows how to add JavaScript files at the bottom of the page for optimal loading performance.
Example #6
This example demonstrates loading module-specific assets using the module assets trigger, keeping your public pages organised and maintainable.
Example #7
This comprehensive example shows how to add custom meta tags for SEO and social media sharing, along with page-specific styling and scripts.