Layout
Layout
Layout view class.
class Layout extends \Hazaar\View\ViewThis view specialization composes multiple child views into a single rendered output stream. It supports appending static layout content, rendering child views with shared helpers/function handlers, and caching the prepared child output for efficient repeated layout retrieval.
Layout instances are typically used as top-level containers for page templates where multiple partial views are aggregated into one response.
Properties
content
Static content prefix prepended to rendered child view output.
private string $contentrenderedViews
public string $renderedViewsviews
private array $viewsMethods
__construct
Creates a new layout view.
public __construct(?string $view, array $data): voidParameters
| Parameter | Type | Description |
|---|---|---|
$view | string | the view file to use for the layout |
$data | array | the data to render the layout with |
__setContent
Sets the content of the layout.
public __setContent(string $content): voidParameters
| Parameter | Type | Description |
|---|---|---|
$content | string | the content to set |
prepare
Prepares the layout for rendering.
public prepare(?array $data): boolThis method prepares the layout by rendering all the views added to it. It adds the layout's helpers to each view, extends the view's data with the layout's data, and renders each view. If the $mergeData parameter is set to true, it also extends the layout's data with each view's data.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | array | optional data to merge into the layout before rendering |
layout
Returns the layout content.
public layout(?array $data): stringThis method prepares the views and merges the data back in, if necessary. The layout content is then returned as a string.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | array | optional data to merge into the layout before rendering |
add
Add a view to the layout.
public add(View $view, ?string $key): ViewThis method will add a view based on the supplied argument. If the argument is a string a new Hazaar\View object is created using the view file named in the argument. Alterntively, the argument can be a Hazaar\View object which will simply then be added to the layout.
Parameters
| Parameter | Type | Description |
|---|---|---|
$view | View | A string naming the view to load, or an existing Hazaar_View object |
$key | string | Optional key to store the view as. Allows direct referencing later. |
remove
Removes a view from the layout.
public remove(string $key): voidParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the view to remove |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000