Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Twig Extensions Deferred

Twig Extensions Deferred Laravel Package

phive/twig-extensions-deferred

A Twig extension for deferring template output. Capture blocks or expressions and render them later, making it easy to collect scripts, styles, or other content in the right place without restructuring your Twig views.

View on GitHub
Deep Wiki
Context7

A Twig extension for deferred rendering in Laravel/PHP applications. It lets you register parts of a template—blocks, partials, or expensive fragments—to be rendered after the main output, so slow logic doesn't block the initial response while still producing complete HTML on the same request.

  • Deferred blocks – queue Twig blocks for rendering at a later point
  • Placeholder tokens – output lightweight markers replaced during final resolution
  • Lazy evaluation – run costly queries or service calls only when resolved
  • Twig-native integration – usable via standard tags, functions, and filters
  • Framework-friendly – drop-in setup through Twig's extension API
Frequently asked questions about Twig Extensions Deferred
What does phive/twig-extensions-deferred do?
It is a Twig extension that lets you capture a rendered block or template fragment and output it later in the template. This is useful for placing scripts, styles, or other markup exactly where they belong in the final rendered page. The capability is narrow compile-time templating sugar, not runtime infrastructure.
Can I use phive/twig-extensions-deferred in a Laravel application?
Only indirectly. Laravel ships Blade as its default template engine, so Twig reaches a Laravel app through a bridge such as rcrowe/twigbridge, which pulls in Twig 3.x. This package targets the legacy pre-namespaced Twig API and will not instantiate on Twig 3 without a port. Adopting it also means adopting a second templating engine, cache layer, and escaping model alongside Blade.
Is phive/twig-extensions-deferred compatible with Twig 3?
No. It uses legacy Twig_Extension, Twig_SimpleFunction, and Twig_TokenParser classes that were removed in favor of namespaced Twig\Extension\AbstractExtension and related APIs in Twig 2.x and 3.x. For Twig 3+ use rybakit/twig-deferred-extension instead. Porting this package means rewriting the token parser and node classes against the current AST API and retesting inheritance, include, embed, and autoescape behavior.
How do I install phive/twig-extensions-deferred?
Composer viability is unverified. The phive/ vendor prefix suggests the package was distributed through phive, the PHAR installer for PHP tooling, rather than necessarily as a PSR-4 Composer library. Confirm that it declares PSR-4 autoloading before relying on composer require; if it is PHAR-only you would be vendoring source files rather than depending on a package. It is only appropriate for legacy Twig 1.x projects.
What Twig and PHP versions does this legacy extension support?
It targets the pre-namespaced Twig API from the Twig 1.x era, not modern Twig 2.x or 3.x. A 2020-era legacy package likely carries a PHP 5.6 or 7.x floor and may use patterns deprecated in PHP 8.x, such as dynamic properties and loose callable strings. Modern Laravel requires PHP 8.1+, so a compatibility audit is mandatory even if you fork it.
What does defer mean in this extension: automatic flush or explicit flush?
The exact semantics must be confirmed in the source and documentation because the details matter. These extensions generally capture named block output at one point and require an explicit flush or render call later, but automatic end-of-render flushing is possible. Verify whether the flush point must live in the parent template and whether autoescape context survives the capture boundary.
How does deferred rendering behave with include, embed, and template inheritance?
This needs explicit verification and testing in your templates. Deferred blocks can be dropped, emitted out of order, or double-escaped without throwing an exception, especially across include, embed, and extends boundaries. Confirm whether the flush must be declared in the parent template and whether captured fragments retain their original autoescape context.
How should I test deferred block rendering?
Add template-level tests that assert the deferred fragment appears exactly once, in the correct order, with the correct escaping across extends, include, and embed. Include negative tests for a missing flush and a duplicate flush. Because failures are silent and content-shaped, assertions on the final rendered output are far more useful than unit-testing the extension class in isolation.
Is phive/twig-extensions-deferred maintained?
No. The repository is explicitly named legacy, the last release was June 2020, and it has a single maintainer with essentially no downstream dependents. There is no issue history or dependent corpus to surface failure modes, so you would own any fork permanently, including future Twig major-version upgrades. Treat it as a small MIT-licensed reference implementation rather than a dependency.
What should I use instead for deferred rendering in modern Twig or Laravel?
For Twig 3+ projects, use rybakit/twig-deferred-extension, the supported modern replacement. In a Laravel application using Blade, use built-in stacks, sections, components, and @push/@stack directives instead of adding Twig. If you genuinely need Twig in Laravel, choose a maintained TwigBridge and confirm Twig version compatibility before evaluating any extension.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle