View Configuration
Configure template paths and compiled view cache.
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' => 'cache/views',
// Allow runtime string template evaluation
'allow_string_evaluation' => true,
];
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' => 'cache/views',
Compiled views are stored in storage/cache/views/.
allow_string_evaluation #
Controls whether ViewEngine::compileString() and ViewEngine::safe() can evaluate runtime template strings.
'allow_string_evaluation' => true,
Set this to false in stricter environments if you do not need runtime string template rendering.
View Resolution Order #
The view engine checks multiple locations for templates:
- User views (
user/views/) - your custom templates - Module views (
modules/*/views/) - module-provided templates - 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 cache:clear
Or clear the compiled view directory manually:
rm -rf storage/cache/views/*
Example Directory Structure #
user/
└── views/
├── layouts/
│ └── main.velvet.php
├── pages/
│ ├── home.velvet.php
│ └── about.velvet.php
├── partials/
│ ├── header.velvet.php
│ └── footer.velvet.php
└── errors/
├── 404.velvet.php
└── 500.velvet.php
Related #
- View Engine - rendering templates
- Templates - template syntax