{"id":51023079,"url":"https://github.com/lemmon/twig-jsx","last_synced_at":"2026-06-21T17:30:56.239Z","repository":{"id":354867825,"uuid":"1212707994","full_name":"lemmon/twig-jsx","owner":"lemmon","description":null,"archived":false,"fork":false,"pushed_at":"2026-04-30T14:57:29.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-30T16:23:20.840Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lemmon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-16T16:44:59.000Z","updated_at":"2026-04-30T15:00:04.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/lemmon/twig-jsx","commit_stats":null,"previous_names":["lemmon/twig-jsx"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/lemmon/twig-jsx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemmon%2Ftwig-jsx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemmon%2Ftwig-jsx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemmon%2Ftwig-jsx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemmon%2Ftwig-jsx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lemmon","download_url":"https://codeload.github.com/lemmon/twig-jsx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lemmon%2Ftwig-jsx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34620358,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-21T02:00:05.568Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-21T17:30:52.900Z","updated_at":"2026-06-21T17:30:56.231Z","avatar_url":"https://github.com/lemmon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twig JSX\n\nJSX-like component syntax for Twig.\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n[![PHP](https://img.shields.io/badge/php-%5E8.1-blue)](https://php.net)\n[![Twig](https://img.shields.io/badge/twig-%5E3.0-green)](https://twig.symfony.com)\n[![CI](https://github.com/lemmon/twig-jsx/actions/workflows/ci.yml/badge.svg)](https://github.com/lemmon/twig-jsx/actions/workflows/ci.yml)\n\nWrite `\u003cAlert {type} important /\u003e` instead of a verbose `{% include %}` call. Twig JSX transforms JSX-like component tags into native Twig `{% include %}` and `{% embed %}` calls at the lexer level — no runtime overhead, no Symfony dependency.\n\n## Requirements\n\n- PHP `^8.1`\n- Twig `^3.0`\n\n## Installation\n\n```bash\ncomposer require lemmon/twig-jsx\n```\n\n## Quick Start\n\n### 1. Register the Extension and Lexer\n\n```php\nuse Lemmon\\TwigJsx\\JSXPreLexer;\nuse Lemmon\\TwigJsx\\AttributeExtension;\n\n$twig = new \\Twig\\Environment($loader);\n$twig-\u003eaddExtension(new AttributeExtension());\n$twig-\u003esetLexer(new JSXPreLexer($twig));\n```\n\n### 2. Create a Component\n\nSave your component in `templates/components/Alert.twig`:\n\n```twig\n{% set type      = props.type|default('info') %}\n{% set important = props.important|default(false) %}\n{% set title     = props.title|default(null) %}\n{% set message   = props.message|default('No message provided.') %}\n\n\u003cdiv class=\"alert alert-{{ type }}{% if important %} alert-important{% endif %}{% if props.class|default('') %} {{ props.class }}{% endif %}\"\n     {{ props.except('type', 'important', 'title', 'message', 'class')|spread }}\u003e\n    {% if title %}\u003cstrong\u003e{{ title }}\u003c/strong\u003e{% endif %}\n    {% block content %}{{ message }}{% endblock %}\n\u003c/div\u003e\n```\n\n### 3. Use It in a Template\n\n```twig\n\u003c!-- Self-closing with shorthand --\u003e\n\u003cAlert {type} important message=\"Everything is great!\" /\u003e\n\n\u003c!-- With children and extra attributes --\u003e\n\u003cAlert type=\"warning\" class=\"shadow-lg\" data-id=\"123\"\u003e\n    \u003cstrong\u003eWait!\u003c/strong\u003e Something needs your attention.\n\u003c/Alert\u003e\n```\n\n## Prop Syntax\n\n| Syntax | Example | Compiles to (inside `props` bag) |\n| :--- | :--- | :--- |\n| **Static** | `type=\"info\"` | `'type': 'info'` |\n| **Expression** | `type={userType}` | `'type': userType` |\n| **Expression** | `count={items\\|length}` | `'count': items\\|length` |\n| **Expression** | `theme={dark ? 'd' : 'l'}` | `'theme': dark ? 'd' : 'l'` |\n| **Shorthand** | `{type}` | `'type': type` |\n| **Boolean** | `important` | `'important': true` |\n\nA quoted value is a **static string** — it is not interpolated. For a dynamic\nvalue, use the expression form: `class={'alert-' ~ type}` rather than\n`class=\"alert-{{ type }}\"`. A quoted value containing a `{{ … }}` output tag is\nrejected with a `SyntaxError` that points at the expression form, instead of\nsilently passing the literal text. (To pass a literal `{{ … }}` through, wrap it\nin a quoted expression: `tpl={'{{ name }}'}`.) See\n[docs/decisions/0001-no-interpolation-in-quoted-props.md](docs/decisions/0001-no-interpolation-in-quoted-props.md)\nfor the reasoning.\n\n## How a Component Reads Its Inputs\n\nEvery prop the caller passes — semantic inputs and HTML attributes alike — arrives in a single\n`props` bag of type `ComponentAttributes`. The component template decides what to extract:\n\n```twig\n{# Destructure semantic inputs as locals #}\n{% set type    = props.type|default('info') %}\n{% set message = props.message|default('') %}\n\n{# Spread the remaining keys as HTML attributes #}\n\u003cdiv class=\"alert-{{ type }}\" {{ props.except('type', 'message')|spread }}\u003e\n    {{ message }}\n\u003c/div\u003e\n```\n\n- `props.key` — read any value\n- `props.except('a', 'b', ...)` — returns a new bag without the listed keys; useful for spreading HTML fallthrough attributes onto the root element\n- `{{ props|spread }}` — renders all entries as HTML attribute pairs\n\n## Configuration\n\n| Option | Default | Description |\n| :--- | :--- | :--- |\n| `directory` | `components` | Subdirectory inside `templates/` where component files are looked up. |\n| `extension` | `.twig` | File extension for component templates. |\n| `prefix` | `\"\"` | Tag prefix. When empty, any Capitalized tag is treated as a component (JSX-style). |\n| `props_variable` | `props` | Name of the variable that holds all props in the component template. |\n| `content_block` | `content` | Twig block name where a bodied tag's children are rendered. |\n\n## Alternatives\n\n- [Symfony UX Twig Component](https://symfony.com/bundles/ux-twig-component/current/index.html) — PHP class-backed components; requires the Symfony UX bundle.\n- [TwigX](https://github.com/alma-oss/twigx-bundle) — similar `\u003cComponent /\u003e` syntax as a Symfony bundle; requires Symfony Config and DI.\n\n## Contributing\n\nBug reports and pull requests are welcome on [GitHub](https://github.com/lemmon/twig-jsx).\n\n## License\n\nMIT. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemmon%2Ftwig-jsx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemmon%2Ftwig-jsx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemmon%2Ftwig-jsx/lists"}