{"id":26543,"library":"twig-to-phtml","title":"twig-to-phtml","description":"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.","status":"active","version":"0.3.4","language":"javascript","source_language":"en","source_url":"git://github.com/NightlyCommit/twig-to-phtml","tags":["javascript","twig","phtml"],"install":[{"cmd":"npm install twig-to-phtml","lang":"bash","label":"npm"},{"cmd":"yarn add twig-to-phtml","lang":"bash","label":"yarn"},{"cmd":"pnpm add twig-to-phtml","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Transpiler is a named export, not a default export.","wrong":"import Transpiler from 'twig-to-phtml'","symbol":"Transpiler","correct":"import { Transpiler } from 'twig-to-phtml'"},{"note":"CommonJS require destructures the named export.","wrong":"const Transpiler = require('twig-to-phtml')","symbol":"Transpiler","correct":"const { Transpiler } = require('twig-to-phtml')"},{"note":"TypeScript type import syntax.","wrong":"import { type Transpiler } from 'twig-to-phtml'","symbol":"Transpiler","correct":"import type { Transpiler } from 'twig-to-phtml'"}],"quickstart":{"code":"import { Transpiler } from 'twig-to-phtml';\n\nconst transpiler = new Transpiler();\n\nconst phtml = transpiler.transpile('{{foo}}');\nconsole.log(phtml); // '<?=$foo?>'","lang":"typescript","description":"Creates a Transpiler instance and transpiles a simple Twig variable into PHTML."},"warnings":[{"fix":"Check the documentation for supported tags and filters. Use only basic syntax.","message":"The transpile() method may not support all Twig constructs; test thoroughly.","severity":"breaking","affected_versions":"0.x"},{"fix":"Monitor the GitHub repository for breaking changes and new releases.","message":"Some Twig features may be deprecated in future releases; keep package updated.","severity":"deprecated","affected_versions":"*"},{"fix":"Always review generated PHTML code before using in production.","message":"The transpiler does not validate PHTML syntax; output may require manual fixes.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use import { Transpiler } from 'twig-to-phtml'","cause":"Imported as default instead of named export.","error":"TypeError: Transpiler is not a constructor"},{"fix":"Run npm install --save-dev twig-to-phtml","cause":"Package not installed or not in node_modules.","error":"Cannot find module 'twig-to-phtml'"},{"fix":"Call transpiler.transpile(twigString) to convert.","cause":"Twig syntax not transpiled; likely transpile() was not called.","error":"Unexpected token '{{' in PHTML output"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}