Registry / serialization / twig-to-phtml

twig-to-phtml

JSON →
library0.3.4jsnpmunverified

A Twig to PHTML transpiler that converts Twig template syntax into PHP (PHTML) code. Version 0.3.4 is the current stable release, with infrequent updates. It differs from alternatives like twig2php by focusing on direct transpilation without runtime dependencies. Designed for build-time use in PHP projects migrating from Twig to native PHP templates. Supports basic Twig constructs like variable output, loops, and conditionals.

npm install twig-to-phtml
INSTALL
IMPORT
SIG · TWIG-TO-PHTML
T
twig-to-phtml
serializationjavascriptv0.3.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Transpiler
import { Transpiler } from 'twig-to-phtml'
import Transpiler from 'twig-to-phtml'
Transpiler is a named export, not a default export.
Transpiler
const { Transpiler } = require('twig-to-phtml')
const Transpiler = require('twig-to-phtml')
CommonJS require destructures the named export.
Transpiler
import type { Transpiler } from 'twig-to-phtml'
import { type Transpiler } from 'twig-to-phtml'
TypeScript type import syntax.

Creates a Transpiler instance and transpiles a simple Twig variable into PHTML.

import { Transpiler } from 'twig-to-phtml'; const transpiler = new Transpiler(); const phtml = transpiler.transpile('{{foo}}'); console.log(phtml); // '<?=$foo?>'
twig-to-phtml --version
Debug
Known issues
breakingThe transpile() method may not support all Twig constructs; test thoroughly.
fix
Check the documentation for supported tags and filters. Use only basic syntax.
affects: 0.x
deprecatedSome Twig features may be deprecated in future releases; keep package updated.
fix
Monitor the GitHub repository for breaking changes and new releases.
affects: *
gotchaThe transpiler does not validate PHTML syntax; output may require manual fixes.
fix
Always review generated PHTML code before using in production.
affects: *
Errors
Common errors & fixes
TypeError: Transpiler is not a constructor
Imported as default instead of named export.
fix
Use import { Transpiler } from 'twig-to-phtml'
Cannot find module 'twig-to-phtml'
Package not installed or not in node_modules.
fix
Run npm install --save-dev twig-to-phtml
Unexpected token '{{' in PHTML output
Twig syntax not transpiled; likely transpile() was not called.
fix
Call transpiler.transpile(twigString) to convert.
Upgrade
Version history
0.3.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
twig-to-phtml — npm install twig-to-phtml · libregistry