Layout
Layout
Layout view class.
class Layout extends \Hazaar\ViewExtends: Hazaar\View
This 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 $contentType: string
renderedViews
public string $renderedViewsType: string
views
private array $viewsType: array
Methods
__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): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | the content to set |
prepare
Prepares the layout for rendering.
public prepare(?array $data): boolReturns: bool
This 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): stringReturns: string
This 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(string|View $view, ?string $key): ViewReturns: Hazaar\View
This 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 | string | Hazaar\View |
$key | string | Optional key to store the view as. Allows direct referencing later. |
remove
Removes a view from the layout.
public remove(string $key): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the view to remove |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000