Documentation · Chapter 09

Build with pages and components.

A page represents a route. A component represents a reusable piece. Both return a tree of View objects.

Every lesson starts from the problem, explains the mechanism, then gives a concrete verification.

A page is the route's visible result

HomePage extends Page and body() returns the visible tree. The route selects the page; body does not need to read global files.

phpaml — zsh
final class GreetingCard extends Component
{
    public function __construct(private string $name) {}
    public function body(): View
    {
        return Section(Heading('Hello ' . $this->name));
    }
}

Components reduce repetition

A component is a PHP class returning View. Pass typed constructor values and keep local presentation together. Reuse it from pages without copying markup.

Native semantics remain visible

Heading, MainContent, Aside, Form, Label, and Button retain their HTML meaning. Accessibility starts from choosing the right component.