API Reference

bind(string $layout): self

Loads the base layout file.

Parameters: Returns: CandidTemplateAdaptor

$tpl = (new CandidTemplateAdaptor('views'))
    ->bind('layout.html');
Throws exception if file not found.
slot(string $slot, string $page, ?string $path = null): CandidTemplate

Injects a template into a layout slot.

Parameters: Returns: CandidTemplate (child template)

$admin = $tpl->slot('content', 'admin');
$dashboard = $admin->slot('content', 'dashboard');
Supports nested layouts via chaining.
include(string $selector, string $page, ?string $path = null): CandidTemplate

Replaces a DOM element using CSS selector.

Parameters:

$header = $tpl->include('#header', 'header');
$header->pick('username')->content('Tamil');
Selector must match exactly one element.
pick(string $key): CandidElement

Selects an element for modification.

Supported selectors:

$tpl->pick('title')->content('Hello');
Duplicate matches may cause exception.
content(mixed $value): self

Sets inner content of element.


$tpl->pick('title')->content('Welcome');
replace(mixed $value): self

Replaces entire element.


$tpl->pick('title')->replace('<h1>New</h1>');
attribute(string $name, mixed $value): self

Sets HTML attribute.


$tpl->pick('btn')
    ->attribute('class', 'btn btn-primary')
    ->attribute('disabled', true);
addLoopItem(string $key): CandidTemplate

Adds a new loop instance.


$item = $tpl->addLoopItem('users');

$item->pick('name')->content('John');
Each call clones the loop template.
addDataFile(string $file): void

Loads external PHP file for data assignment.


$tpl->addDataFile('data.php');

// data.php
$this->pick('title')->content('Loaded');
render(): string

Renders final HTML output.


echo $tpl->build()->render();
Final step after all assignments.