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 Js Laravel Package

forknetwork/twig-js

Brings Twig.js to Laravel so you can render Twig templates in the browser and share the same template syntax across PHP and JavaScript. Integrates Twig.js assets with your Laravel app for consistent, client-side templating.

View on GitHub
Deep Wiki
Context7

forknetwork/twig-js is a Laravel package that brings Twig.js to the browser, letting you reuse Twig templates across server-side PHP and client-side JavaScript. It provides a lightweight bridge for rendering Twig views in JavaScript without duplicating template logic.

  • Reuse existing Twig templates on the frontend
  • Render Twig.js templates directly in JavaScript
  • Laravel-friendly configuration and setup
  • Supports Twig inheritance, includes, and filters
  • Keeps frontend and backend template syntax aligned
Frequently asked questions about Twig Js
Does forknetwork/twig-js integrate with Blade or Laravel's view system?
No. forknetwork/twig-js is a JavaScript templating engine (a fork of twig.js), not a PHP library, so it has no Blade compiler integration, no view finder, and no service provider. Its only defensible role in a Laravel codebase is the frontend asset layer: rendering Twig-syntax templates in the browser. If your application is Blade-based, there is no architectural slot for this package and it should be rejected.
How do I install forknetwork/twig-js in a Laravel app using Vite?
Treat it as vendored code rather than a managed dependency. Copy the built distribution into resources/js/vendor/twig/, record the source commit in a VENDORED.md, and wrap the UMD build in a thin ES module that exposes something like renderTemplate(name, context). Configure Vite/Rollup interop for the UMD wrapper so the rest of your app never imports the library directly. Adding it via Composer buys you nothing beyond an asset location and creates a false impression of dependency lifecycle management.
Why does a JavaScript library have a Composer package name?
The vendor/package name is misleading: the deliverable is JavaScript source and dist files, not PHP classes. Composer autoloading provides no functional benefit here, and there is no facade, config file, or artisan command to rely on. Real integration means pulling the distribution into your JS pipeline and pinning a commit or tarball. Remove any Composer entry if one exists so nobody assumes it is patched or version-managed.
Which Laravel or PHP versions does this package support?
PHP and Laravel version constraints are essentially irrelevant because the library runs in the browser, not in PHP. The real constraints are your browser targets, your Node LTS build pipeline, and your bundler. The 2019 vintage implies ES5-era output and a UMD wrapper, so expect to add interop configuration for Vite or Rollup.
When is Twig.js actually worth using in a Laravel project?
Only when the backend already emits Twig templates, typically because Laravel sits in front of or alongside a Symfony/Twig service, or because TwigBridge is in use and the frontend needs progressive enhancement or client-side re-render of the same templates. In a Blade plus Livewire, Alpine, or Vue stack, it adds a second template dialect for zero benefit. Server-side pre-rendering that returns HTML from your API is usually the cheaper alternative.
Is forknetwork/twig-js safe and maintained enough for production?
The project profile is a serious concern: roughly two stars, zero dependents, and a last release around 2019-03-14, meaning no security patching and no compatibility work for modern bundlers. A two-star fork also carries supply-chain ambiguity, since provenance, maintainer identity, and divergence from upstream twig.js are undocumented. If you adopt it, budget to fork and maintain it internally rather than assuming upstream will fix escaping or sandbox issues.
Should I use upstream twigjs/twig.js instead of this fork?
Yes, upstream twigjs/twig.js is the default choice unless you can document exactly what ForkNetwork changed and why that change is load-bearing for you. A 2019 two-star fork with no dependents gives you no patch stream and no community pressure on parity bugs. Adopting an undocumented fork means owning the maintenance burden yourself.
How do I keep client-side Twig output identical to server-side Twig output?
Twig.js historically lags Twig PHP in filters, whitespace control, and autoescape semantics, so parity bugs are a realistic failure mode rather than an edge case. Add a fixture suite that renders a representative set of real templates on both sides and compares the resulting HTML. Prototype parity on three to five actual templates before committing, and pin the Twig PHP version the client is expected to mirror.
Does twig.js work with a strict Content Security Policy?
No, not without relaxation. twig.js compiles templates using new Function, which is incompatible with a strict script-src directive unless unsafe-eval is permitted. If your Laravel app enforces a tight CSP, either precompile templates at build time, move rendering to the server, or plan an explicit exception for the paths that need it.
What are the alternatives to adding Twig.js to a Laravel frontend?
The simplest alternative is to render the Twig templates server-side and return finished HTML, avoiding a second template engine entirely. If you need client-side interactivity, Blade components plus Alpine.js, Livewire, or Vue cover most cases without introducing Twig syntax in the browser. Where Twig parity is a hard requirement and the backend is Twig-based, use upstream twig.js with a parity test suite rather than a stale fork.
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.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo