Partial
in package
Class for rendering partials using isolated arguments.
Renderer class for including PHP partial files with dynamic parameters. Allows rendering of reusable PHP templates (partials) by passing variables as an associative array. Uses output buffering to capture and return rendered content.
Table of Contents
Properties
- $partialsPath : string
- Base path to the partials folder
Methods
- __construct() : mixed
- Constructor
- render() : void
- Renders a partial file with the given parameters
Properties
$partialsPath
Base path to the partials folder
private
string
$partialsPath
Methods
__construct()
Constructor
public
__construct(string $partialsPath) : mixed
Initializes the partial renderer with the base path to the partials folder. Validates that the partials directory exists.
Parameters
- $partialsPath : string
-
Absolute or relative path to the partials folder
Tags
render()
Renders a partial file with the given parameters
public
render(string $path, array<string|int, mixed> $args) : void
Includes a PHP partial file and makes variables available within its scope. The file extension '.php' is automatically appended to the path. Variables are extracted from the $args array and made available as individual variables. Uses output buffering to capture the partial's output.
Parameters
- $path : string
-
Path to the partial file relative to partialsPath (without .php extension)
- $args : array<string|int, mixed>
-
Associative array of variables to pass to the partial
Tags
Return values
void —Outputs the rendered partial content