Installation:
composer require alexvasilyev/mthaml
Add the service provider to config/app.php under providers:
Alexvasilyev\Mthaml\MthamlServiceProvider::class,
Basic Usage:
.haml.php file (e.g., resources/views/layouts/haml.php).!! 5
%html
%head
%title My App
%body
= $message
use Alexvasilyev\Mthaml\Mthaml;
public function index(Mthaml $haml)
{
return $haml->render('layouts.haml', ['message' => 'Hello, World!']);
}
First Use Case:
Hybrid Blade + HAML:
layouts.haml) and Blade for dynamic components.// In a controller
return view('layouts.haml', [
'content' => view('components.card', ['data' => $data])
]);
Partial Reusability:
resources/views/partials/_*.haml.$haml->renderPartial('partials._header', ['title' => 'Home']);
Dynamic Compilation:
$haml->setCachePath(storage_path('framework/views'));
Laravel Mix:
Combine HAML compilation with asset pipelines by extending mix.js() or mix.webpack() to trigger HAML preprocessing.
Form Handling:
Use HAML for form layouts while leveraging Laravel’s Form facade for inputs:
= Form::open()
%div.field
= Form::label('email')
= Form::email('email')
= Form::close()
API Responses: Return HAML-rendered HTML for API-driven frontend frameworks (e.g., React/Vue):
return response($haml->render('api.response.haml', $data), 200);
Deprecated Syntax:
No Blade Directives:
@stack, @yield, or @include directives. Use partials or manual concatenation:
$content = $haml->render('partials._sidebar');
echo $haml->render('layout.haml', ['sidebar' => $content]);
Escaping Issues:
|raw or use Laravel’s @escape equivalent:
= e($user->input) // Manual escaping (if supported)
Namespace Conflicts:
home.haml vs. home.blade.php).Compilation Errors:
storage/framework/views.dd($haml->render('view.haml', $data)) to inspect raw output.Caching Quirks:
php artisan view:clear
Custom Filters:
|upcase):
// In a service provider
$haml->addFilter('upcase', function($value) {
return strtoupper($value);
});
Usage in HAML:
= $message | upcase
Multi-Language Support:
Mthaml class to support additional languages (e.g., Twig) by extending the base parser.Preprocessing:
View::composer() to preprocess HAML before rendering:
View::composer('*.haml', function($view) {
$view->with('preprocessed_data', $this->transform($view->data));
});
How can I help you explore Laravel packages today?