Docs LATEST

View Configuration

Configure template paths and compiled view cache.

Configuration

View configuration lives in config/view.php. Control where templates are loaded from and where compiled templates are cached.

Full Configuration Example #

return [
    // Root directory for user views (relative to base_path)
    'path' => 'user/views',
    
    // Compiled template cache directory (relative to storage_path)
    'compiled' => 'views',
];

Configuration Options #

path #

Where the view engine looks for templates. This is relative to your project root (base_path).

'path' => 'user/views',

With this config, $view->render('pages/home') loads user/views/pages/home.php.

compiled #

Where compiled templates are cached. This is relative to storage_path().

'compiled' => 'views',

Compiled views are stored in storage/views/.

View Resolution Order #

The view engine checks multiple locations for templates:

  1. User views (user/views/) - your custom templates
  2. Module views (modules/*/views/) - module-provided templates
  3. Core views (src/views/) - framework defaults

This allows you to override any template by placing a file with the same name in your user views directory.

Multi-Tenancy Behavior #

When tenancy is enabled and the path starts with user/:

// Config
'path' => 'user/views',

// Without tenancy
// Resolves to: user/views/

// With tenant "acme"
// Resolves to: user/tenants/acme/views/

The compiled cache (storage/views/) is also tenant-scoped automatically.

Clearing Compiled Views #

Compiled templates are cached for performance. Clear them when updating templates:

./velvet view:clear

Or delete the directory manually:

rm -rf storage/views/*

Example Directory Structure #

user/
└── views/
    ├── layouts/
    │   └── main.php
    ├── pages/
    │   ├── home.php
    │   └── about.php
    ├── partials/
    │   ├── header.php
    │   └── footer.php
    └── errors/
        ├── 404.php
        └── 500.php