generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Abdelkarim Mateos Sanchez edited this page Dec 12, 2025
·
3 revisions
A powerful, framework-agnostic mustache template resolver for PHP applications with first-class Laravel integration.
Laravel Mustache Resolver provides a flexible and extensible system for resolving mustache-style template expressions like {{User.name}}, {{Device.status}}, or complex compound expressions with conditions and math operations.
- Framework Agnostic: Core functionality works without Laravel
- First-class Laravel Integration: Service provider, facade, and Eloquent support
- Extensible Resolver Pipeline: Add custom resolvers for your domain
- Compound Expressions: USE clause syntax for complex queries
- Temporal Expressions: Time-based conditions, CRON support, weekday/weekend checks
- 26 Built-in Formatters: Date/time, numeric, and string transformations
- Safe Math Expressions: Arithmetic without eval()
- Condition Validation: Throw exceptions when conditions fail
- Full Test Coverage: 526+ tests with strict typing
use AichaDigital\MustacheResolver\Core\Context\ResolutionContext;
use AichaDigital\MustacheResolver\Core\Pipeline\PipelineBuilder;
// Build a resolution pipeline
$pipeline = PipelineBuilder::default()->build();
// Create context with your data
$context = ResolutionContext::fromArray([
'User' => $user, // Eloquent model
'Device' => $device, // Another model
'config' => $configArray, // Array data
]);
// Parse and resolve a template
$parser = new MustacheParser();
$tokens = $parser->parse('Hello {{User.name}}, your device {{Device.serial}} is {{Device.status}}');
foreach ($tokens as $token) {
$value = $pipeline->resolve($token, $context);
// Replace in template...
}- Installation
- Basic Usage
- Resolvers
- Compound Expressions
- Formatters
- Math Expressions
- Temporal Expressions
- Configuration
- Laravel Integration
- Testing
- API Reference
| Type | Example | Description |
|---|---|---|
| Model | {{User.name}} |
Access model attributes |
| Relation | {{User.department.name}} |
Traverse relationships |
| Collection | {{User.posts.*.title}} |
Map over collections |
| Variable | {{$myVariable}} |
Context variables |
| Dynamic | {{Device.$config.field}} |
Dynamic field access |
| Null Coalesce | {{User.nickname ?? 'Guest'}} |
Default values |
| Function | {{now()}} |
Function calls |
| Compound | USE {var} => {{expr}} && ... |
Complex expressions |
| Temporal | {{TEMPORAL:isDue('weekday')}} |
Time-based conditions |
| Now | {{NOW:format('Y-m-d')}} |
Current datetime |
| Today | {{TODAY:startOfDay}} |
Today's date helpers |
- PHP 8.2 or higher
- Laravel 10, 11, or 12 (optional)
This package is licensed under the AGPL-3.0-or-later license.
Contributions are welcome! Please see our contribution guidelines before submitting a pull request.
Next: Installation →
Laravel Mustache Resolver | GitHub | License: AGPL-3.0-or-later