Installation
composer require wirbelwild/kiwa-core
Add the service provider to config/app.php:
'providers' => [
// ...
Wirbelwild\Kiwa\Core\KiwaServiceProvider::class,
],
Basic Configuration Publish the config file:
php artisan vendor:publish --provider="Wirbelwild\Kiwa\Core\KiwaServiceProvider" --tag="config"
Update config/kiwa.php with your site’s root directory (e.g., public_html).
First Route
Define a route in routes/web.php:
use Wirbelwild\Kiwa\Core\Facades\Kiwa;
Kiwa::get('/', function () {
return Kiwa::view('home');
});
Run the Dev Server
php artisan kiwa:serve
Access http://localhost:8000 to see your static site.
Create a Twig template (resources/views/home.twig):
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
</html>
Render it via the route above. Kiwa compiles Twig to static HTML on demand.
Kiwa::view() to render Twig templates dynamically during development. In production, pre-generate static HTML with:
php artisan kiwa:generate
// app/Console/Kernel.php
protected function schedule(Schedule $schedule) {
$schedule->command('kiwa:generate')->daily();
}
Kiwa::get('/blog/{slug}', function ($slug) {
return Kiwa::view('blog.post', ['slug' => $slug]);
});
php artisan kiwa:generate --paths="blog/*"
// routes/web.php
Kiwa::get('/css/app.css', function () {
return file_get_contents(public_path('css/app.css'));
});
Kiwa::asset() helper for versioned assets:
<link rel="stylesheet" href="{{ asset('css/app.css?v=1.0') }}">
Kiwa::get('/products', function () {
return Kiwa::view('products');
})->middleware(\Wirbelwild\Kiwa\Core\Middleware\CacheHeaders::class);
Kiwa::get('/api/posts', function () {
return response()->json(['posts' => Post::all()->toArray()]);
});
CacheHeaders middleware.Twig Auto-Reloading
kiwa:generate.php artisan cache:clear && php artisan kiwa:generate
Route Caching Conflicts
generate command before deploying.Asset Paths in Production
/css/app.css) break if the site root changes.Kiwa::asset() helper or configure asset_url in kiwa.php.Dynamic Content in Static Pages
Enable Debug Mode:
// config/kiwa.php
'debug' => env('APP_DEBUG', false),
This shows Twig errors and route debug info.
Check Generated Files:
php artisan kiwa:generate --dry-run
Lists files that would be generated without writing them.
Custom Template Engines
Wirbelwild\Kiwa\Core\Engines\EngineInterface to support other templating languages (e.g., Blade).Pre-Generation Hooks
KiwaServiceProvider::boot() to add logic before static generation:
public function boot() {
Kiwa::extend('pre_generate', function () {
// Pre-process data (e.g., fetch latest blog posts)
});
}
Custom Storage Adapter
Wirbelwild\Kiwa\Core\Storage\StorageInterface to write static files to S3, etc.Middleware for Static Validation
Kiwa::get('/validate', function () {
return Kiwa::view('home')->middleware(ValidateStaticLinks::class);
});
How can I help you explore Laravel packages today?