swp/templates-system
A Laravel package for building and managing reusable templates. It supports database-backed templates, dynamic variable placeholders, and seamless rendering in PHP applications, making content flexible and maintainable.
The package is a Symfony-oriented Twig templating layer (swp/templates-system) rather than a Laravel-specific package; treat this as "integrate a framework-agnostic component", not "drop in a facade".
composer require swp/templates-system
Immediately after install, do three checks before writing code:
symfony/twig-bridge, doctrine/*). Run composer why-not swp/templates-system and expect conflicts with Laravel 9+/Symfony 5+. Expect to either pin older versions in an isolated service, or to vendor-fork it.gimme style tags) from a context. That is the real value — editors manage templates and pull content without PHP code.Read src/ in this order:
*Bundle directory — this is the Symfony wiring you'll have to port to a Laravel service providerFirst use case: store a template inside the admin, attach a template_name to a content record, and render it through a Twig environment that has the package's loader and extensions registered, returning HTML from a controller.
// provider boot — class names approximate; verify against src/
$this->app->singleton(\Twig\Environment::class, fn ($app) => new \Twig\Environment(
$app->make(\Twig\Loader\LoaderInterface::class),
['cache' => storage_path('framework/twig'), 'debug' => config('app.debug')]
));
php artisan make:provider TemplatesSystemServiceProvider. Bind the Twig Environment, LoaderInterface, and the Gimme context as singletons. Laravel's container is close enough to Symfony's that you can hand-translate the bundle's XML/YAML service definitions rather than registering the bundle.ChainLoader-style class implementing Twig\Loader\LoaderInterface is the cleanest seam; it also makes ArrayLoader-backed tests trivial.template_name attribute; controller resolves it via a TemplateRenderer service. Keeps Twig out of controllers.name, source, type, cache_version, tenant_id. Bump cache_version on save and invalidate Twig's cache for that name.TemplateContext) so fetch behavior is testable without HTTP.packages/, and own the tests. Do not expect fixes.storage/framework/twig) and invalidate on template save; Environment::load() respects isFresh, so a version bump on the source is the simplest fix.debug: true and strict_variables: true; missing context variables will then fail loudly instead of rendering blanks.Template record once per route and store it in Redis; re-resolving on every request is the main performance cost.How can I help you explore Laravel packages today?