{"id":13513338,"url":"https://github.com/mortenson/twig-components","last_synced_at":"2026-01-02T14:04:59.349Z","repository":{"id":69715825,"uuid":"113787945","full_name":"mortenson/twig-components","owner":"mortenson","description":"An experimental repository to use Twig templates in Web Components","archived":false,"fork":false,"pushed_at":"2018-03-25T05:29:20.000Z","size":184,"stargazers_count":29,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-01-21T09:48:48.085Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mortenson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-12-10T22:18:05.000Z","updated_at":"2024-11-24T22:05:35.000Z","dependencies_parsed_at":"2023-07-19T19:30:32.511Z","dependency_job_id":null,"html_url":"https://github.com/mortenson/twig-components","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mortenson%2Ftwig-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mortenson%2Ftwig-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mortenson%2Ftwig-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mortenson%2Ftwig-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mortenson","download_url":"https://codeload.github.com/mortenson/twig-components/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243609403,"owners_count":20318785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2024-08-01T04:00:53.060Z","updated_at":"2026-01-02T14:04:59.343Z","avatar_url":"https://github.com/mortenson.png","language":"HTML","funding_links":[],"categories":["Projects using Twig with JavaScript"],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/twig-components.svg)]() [![Build Status](https://travis-ci.org/mortenson/twig-components.svg?branch=master)](https://travis-ci.org/mortenson/twig-components)\n\n# Twig Components\n\nAn experimental repository to use Twig templates in Web Components.\n\nThis project provides a base web component that others can extend, and\nspecifications for what distributed Twig components should look like.\n\nBeyond being useful to users already using something like [Twig.js](https://github.com/twigjs/twig.js)\n, using Twig templates opens the door to server side rendering _without_\nJavascript. This is critical for progressive enhancement, SEO, and\naccessibility.\n\nIf you're using PHP and want to try out server side rendering, check out\n[twig-components-ssr](https://github.com/mortenson/twig-components-ssr).\n\n# Installation\n\n`npm install --save-dev twig-components`\n\n# Extending the base component\n\nThe base component in `twig-base.js` can be extended minimally by implementing\nthe `observedAttributes` and `getTemplate` methods:\n\n```js\nimport TwigBase from 'twig-components/twig-base';\n\nclass MyComponent extends TwigBase {\n\n  static get observedAttributes() {\n    return ['name'];\n  }\n\n  getTemplate() {\n    return 'Hello {{ name }}!';\n  }\n\n}\n\ncustomElements.define('my-component', MyComponent);\n```\n\nThen, when `\u003cmy-component name=\"World\"\u003e\u003c/my-component\u003e` is placed on a page,\nthe template will be compiled and rendered with the current attributes.\n\nYou can read the [Wiki page](https://github.com/mortenson/twig-components/wiki/Building-your-first-component-from-scratch) on this topic for more detailed information.\n\n# Creating a component library with Webpack\n\nWhile extending the base component in the above example seems easy, getting it\nworking in production has a few hard problems:\n\n- Distributing one JS file for multiple components\n- Supporting older browsers\n- Bundling Web Component polyfills\n- Splitting up assets into distinct files (ex: .js, .twig, and .scss)\n- Building a templates.json file\n\nTo ease some of this pain, a Yeoman generator is available to quickly spin up a\nnew component library, which has a complex Webpack configuration that does all\nof this out of the box. See [generator-twig-components-webpack](https://github.com/mortenson/generator-twig-components-webpack)\nfor more details.\n\n# Example project\n\nAn example project with some useful Twig Components is maintained at [twig-components-example](https://github.com/mortenson/twig-components-example). If you want to view a live demo of the example project, [click here](https://mortenson.coffee/twig-components-example/).\n\nThe project was built using Yeoman, please check it out!\n\n# Distribution specification\n\nTo help keep various distribution and bundling methods consistent, a\nspecification is maintained in [DISTRIBUTION.md](DISTRIBUTION.md).\n\n# Running tests\n\nTests for the base class are written with the [web-component-tester](https://github.com/Polymer/web-component-tester)\npackage.\n\nTo run tests:\n\n1. Ensure that Java is available in your `PATH`\n1. Run `npm install -g bower rollup web-component-tester`\n1. Run `npm run test`\n\n# Todo\n\n- [x] Create base custom element\n- [x] Import SCSS/Twig from a file during build\n- [x] Create a Yeoman generator for new components\n- [x] Figure out what production packaging looks like\n- [x] Write unit test coverage for the base class\n- [x] Implment server-side-rendering with PHP Twig\n- [x] Write a ton of docs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmortenson%2Ftwig-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmortenson%2Ftwig-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmortenson%2Ftwig-components/lists"}