API Reference
bind(string $layout): self
Loads the base layout file.
Parameters:$layout– Layout file name (without path)
$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:$slot– Slot name (data-slot)$page– Template file name$path– Optional subfolder
$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:$selector– CSS selector (#id recommended)$page– Template file
$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:- id
- name
- tag
$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.