Views

Views in PointArt are plain .php files — no template engine, no compilation, no build step. HTML mixed with <?= $var ?> and <?php ?> blocks.

Namespace PointStart\Core — Renderer

Rendering a View

Renderer::render(string $view, array $data = []): string
ParameterDescription
$view View name — maps to app/views/<name>.php. Use dot notation for grouping (e.g. 'user.list'app/views/user.list.php)
$data Associative array of variables to pass. Each key becomes a local variable inside the view

How It Works

The Renderer::render() method:

  1. Checks if the view file exists at VIEW_DIRECTORY/{$view}.php
  2. Calls extract($data) so array keys become local variables
  3. Starts output buffering with ob_start()
  4. Requires the view file (uses require, not require_once, so the same view can be rendered multiple times)
  5. Returns the buffered content with ob_get_clean()

Passing Data to Views

Every key in $data is extracted into the view scope:

// In the controller
return Renderer::render('user.list', [
    'users' => $users,     // available as $users in the view
    'title' => 'All Users', // available as $title in the view
]);
<!-- app/views/user.list.php -->
<h1><?= htmlspecialchars($title) ?></h1>
<?php foreach ($users as $user): ?>
    <p><?= htmlspecialchars($user->name) ?> — <?= htmlspecialchars($user->email) ?></p>
<?php endforeach; ?>

Views Without Data

For static pages or error pages, omit the second argument:

return Renderer::render('user.notfound');

Layout Pattern

Since views are plain PHP, you can compose layouts by rendering content first, then wrapping it in a layout view:

// Render the content fragment
$content = Renderer::render('user.list', ['users' => $users]);

// Wrap in the layout
return Renderer::render('_layout', [
    'content'   => $content,
    'pageTitle' => 'All Users',
]);
<!-- app/views/_layout.php -->
<!DOCTYPE html>
<html>
<head>
    <title><?= htmlspecialchars($pageTitle) ?></title>
</head>
<body>
    <?= $content ?>
</body>
</html>
No Nesting Issues This works because Renderer::render() returns a string. The inner render completes and returns its HTML before the outer render begins — no buffer conflicts.

File Organization

Place all view files in app/views/. The dot in the view name is part of the filename, not a directory separator:

View NameFile Path
'user.list'app/views/user.list.php
'user.show'app/views/user.show.php
'_layout'app/views/_layout.php
'home'app/views/home.php

Next: Configuration →