{"id":15048072,"url":"https://github.com/github/template-parts","last_synced_at":"2025-10-23T18:04:14.759Z","repository":{"id":37544061,"uuid":"283752196","full_name":"github/template-parts","owner":"github","description":"An implementation of the Template Parts proposal","archived":false,"fork":false,"pushed_at":"2025-03-28T22:15:00.000Z","size":769,"stargazers_count":158,"open_issues_count":6,"forks_count":18,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-04-01T08:39:09.131Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.github.io/template-parts/examples/","language":"TypeScript","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/github.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-30T11:19:35.000Z","updated_at":"2025-03-28T05:30:26.000Z","dependencies_parsed_at":"2024-06-18T15:18:21.554Z","dependency_job_id":"609cdf56-319c-4fd4-9612-45a22e123c37","html_url":"https://github.com/github/template-parts","commit_stats":{"total_commits":157,"total_committers":10,"mean_commits":15.7,"dds":"0.22292993630573243","last_synced_commit":"8f38806c6cf7e77d2d07c0316a2c970284120afe"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ftemplate-parts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ftemplate-parts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ftemplate-parts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/github%2Ftemplate-parts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/github","download_url":"https://codeload.github.com/github/template-parts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809964,"owners_count":20999816,"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-09-24T21:07:43.384Z","updated_at":"2025-10-23T18:04:14.663Z","avatar_url":"https://github.com/github.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Template Parts\n\nThis library is designed as a \"ponyfill\" library that implements the design in the [TemplateInstance proposed whatwg spec][spec] that has been proposed in order to address [whatwg/html#2254](https://github.com/whatwg/html/issues/2254).\n\n[spec]: https://github.com/w3c/webcomponents/blob/159b1600bab02fe9cd794825440a98537d53b389/proposals/Template-Instantiation.md\n\nThis implements the minimally viable parts of the proposal, to provide something that works, but should be easy to drop if the Template Parts Proposal lands.\n\nTo reiterate the example in the above proposal, given a template such as:\n\n```\n\u003ctemplate id=\"foo\"\u003e\n  \u003cdiv class=\"foo {{y}}\"\u003e{{x}} world\u003c/div\u003e\n\u003c/template\u003e\n```\n\nWe'd like `{{x}}` and `{{y}}` to be **template parts**, exposed as JavaScript objects which can be manipulated.\n\nWith this library, and that given template, one could implement the following:\n\n```js\nimport {TemplateInstance} from '@github/template-parts'\n\nconst tpl = new TemplateInstance(document.getElementById('some-template'), { x: 'Hello', y: 'bar'})\n\ndocument.appendChild(tpl)\n```\n\nA `TemplateInstance` instance is a subclass of `DocumentFragment` - containing the cloned contents of the template. It also has an `update(params: unknown): void` method - which when called will run the given \"processor\", with the new `params`.\n\nThis library has a default \"processor\": `propertyIdentity` which implements basic functionality of applying the params object values to the Template Parts (it is effectively `part.value = params[part.expression]`)\n\nIn addition, there is a `propertyIdentityOrBooleanAttribute` export which adds the capability of toggling `boolean` style attributes like `hidden` or `input.required`.\n\nTo use the `propertyIdentityOrBooleanAttribute`, import it and pass it as a third argument to the `TemplateInstance` constructor:\n\n\n```js\nimport {TemplateInstance, propertyIdentityOrBooleanAttribute} from '@github/template-parts'\n\n// This will simply replace `{{x}}` with `\"Hello\"` and `{{y}}` with `\"bar\"`\nconst tpl = new TemplateInstance(document.getElementById('foo'), { x: 'Hello', y: 'bar'})\n\n// The `propertyIdentityOrBooleanAttribute` processor will check for `false`/`true` values which map to Template Part values that are assigned to attributes, and add/remove the attribute.\nconst tpl = new TemplateInstance(document.getElementById('foo'), { x: 'Hello', hidden: false}, propertyIdentityOrBooleanAttribute)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Ftemplate-parts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgithub%2Ftemplate-parts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgithub%2Ftemplate-parts/lists"}