Repository navigation
Developer Guide Views and Resources
Developer Guide · Controllers · Storage
Internals: Rendering, View, Render, Blade integration, Storage.
Controller extends View, which extends Render. Use $this->view(['key' => $value]) in an action and return the View. The view directory must include its trailing separator because getViewContent() concatenates directory + viewName + .awt.php. The route sets viewName to its action; change $this->viewName when the template differs.
The following replaces the first tutorial's template with a layout. DemoSite/views/templates/main.awt.php:
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>{{ $title }}</title></head>
<body>@yield('content')</body>
</html>DemoSite/views/index.awt.php:
@extends('templates.main')
@section('content')
<h1>{{ $title }}</h1>
@if(isset($items))
<ul>@foreach($items as $item)<li>{{ $item }}</li>@endforeach</ul>
@endif
@endsectionBladeOne supplies layout/section/include/loop/condition directives and escaped {{ }} output. Use raw {!! !!} only for trusted HTML. Template data comes from the view bundle; it is also assigned to object properties during preparation. Avoid keys that overwrite renderer/controller configuration. View::view() initially includes the template PHP file, then render() compiles/runs the Blade template; PHP side effects in a template can therefore run more than once. Keep database mutations and request processing in controllers/services.
Compiled views are stored under COMPILED (awt_data/storage/framework/cache/compiled/) with MODE_AUTO. Bootstrap returns the DOM serialization after loading compiled HTML, so exact whitespace/document markup may differ from the source. It does not stream the initial included output as the final page.
| Template/API | Meaning |
|---|---|
@asset('css/main.css') |
HOSTNAME + configured localAssetPath + file suffix. The tutorial sets the package views/assets root. |
@url('hello') |
Builds HOSTNAME + /hello from a literal expression. |
@resource('views/assets/css/main.css') |
Resolve in this view's package; encode a package resource URL at render time. |
@resource('MessageHub:assets/logo.svg', true) |
Resolve an explicit package path, raising ResourceException if missing. |
@csrf |
Render the session CSRF hidden field. |
@data(...) |
Legacy awt_data/media/packages URL generation; inconsistent with current storage tree. Prefer Resource or a registered StorageEntry URL. |
For @asset create the actual file, e.g. DemoSite/views/assets/css/main.css. Helpers such as @asset/@url parse literal expressions; do not assume arbitrary PHP expressions work like upstream helpers. With the recommended public-only document root, package files are served through the framework controller, not direct filesystem aliases.
Excerpt in a controller action, with its context initialized:
$resources = new \vfs\resource\Resource($this->packageName);
$path = $resources->get('views/assets/css/main.css', true);
$other = $resources->get('MessageHub:assets/logo.svg');get() returns a filesystem path or null; must=true throws on a miss. A bare filename searches recursively and returns the first matching name—use a relative path when duplicates exist. Resource uses package-owned maps, caches them with filesystem watching, and rejects traversal/null/backslash aliases. ResourceBuilder avoids recursively following descendant directory symlinks.
Internal lookup includes PHP/source files because components may need them. PublicResource separately permits only readable in-root files with allowed extensions under assets, public, views/assets, data, css, js, images, fonts, videos or audio; hidden path segments are denied. Therefore resolving an internal file does not guarantee its URL can be served. Registered storage uses /storage/{id}/{name} and a separate authorization pipeline.
Listen to renderer.ready, whose bundle contains renderer. The listener can call getDom(), replaceElementsByClassname(), insertAfterByClassname(), insertIntoByClassname() or insertBeforeByClassname(). These take a DOMDocument with a valid document element. insertIntoByClassname() checks initialized DOM and a simple class-name pattern. Return an array to satisfy IEventListener. Register before render() runs.
View rendering catches Throwable, prints an error message and returns an empty string; the global handler may not receive that failure. Account for this limitation when diagnosing incomplete pages. Template rendering and exception rendering both need DOM/compiled-cache permissions as applicable.
AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes