The past 10 years I have been running Laravel, brought there due to Blade one day. Now I developed a great love for Blade templating engine and wanted to bring it to the Marko Framework.
composer require vanvanni/marko-bladeThis automatically installs marko/view.
Configure via the view config key:
return [
'cache_directory' => '/path/to/cache',
'extension' => '.blade.php',
'auto_refresh' => true, // Set false in production
'strict_types' => false, // Blade does not support strict types
];Templates are rendered using the module namespace syntax:
use Marko\View\ViewInterface;
$view->render('blog::post/index', ['posts' => $posts]);The format is module::path/to/template where:
moduleis the module name (e.g.,blog,admin)path/to/templateis the path withinresources/views/
Use renderToString() when you need the raw HTML:
$html = $view->renderToString('blog::email/welcome', $data);All Blade directives work out of the box:
@extends('blog::layout')
@section('content')
@foreach($posts as $post)
@include('blog::post.item', ['post' => $post])
@endforeach
@endsectionIncludes must use the module namespace format:
@include('blog::post/list/item', ['post' => $post])
@include('blog::pagination/index', ['pagination' => $posts])Relative paths (../) are not supported. This ensures consistent syntax throughout templates.
Anonymous Blade components are supported:
<x-blog::alert type="error" :message="$message" />marko-blade requires illuminate/view, which in turn requires illuminate/support. Both illuminate/support and marko/vite (via marko/env) define a global env() helper.
Because both packages use function_exists('env') guards, no fatal error occurs. In practice, Laravel's env() typically loads first (it is a deeper dependency in Composer's graph) and is used. Both implementations are compatible for typical config usage — both coerce 'true' → true, 'false' → false, 'null' → null, and 'empty' → ''.
illuminate/support lists vlucas/phpdotenv as a suggested dependency, but its Env class cannot function without it. marko-blade explicitly requires vlucas/phpdotenv so Laravel's env() works correctly in any Marko project, even when the framework itself is not installed.
When marko/vite is installed and enabled, marko-blade automatically registers a @viteHeadTags directive:
<!DOCTYPE html>
<html>
<head>
@viteHeadTags
<title>My App</title>
</head>
<body>
...
</body>
</html>By default, it uses the entry point configured in config/vite.php (vite.entry). You can also pass a specific entry:
@viteHeadTags('app/web/resources/js/app.js')In development mode (vite.useDevServer = true), this emits <script type="module"> tags pointing at the Vite dev server. In production, it reads the manifest and emits hashed <script>, <link rel="stylesheet">, and <link rel="modulepreload"> tags.
- Strict Types: Blade does not support
strict_typesbecause compiled templates areincluded at runtime. - Auto Refresh: When
auto_refreshisfalse, templates are only compiled once. In production, you should set this tofalse.
MIT