{"id":15389477,"url":"https://github.com/jgarber623/templatetemplate","last_synced_at":"2025-10-22T21:22:52.986Z","repository":{"id":31137678,"uuid":"126988519","full_name":"jgarber623/TemplateTemplate","owner":"jgarber623","description":"A very small JavaScript \u003ctemplate\u003e manipulation library.","archived":false,"fork":false,"pushed_at":"2025-02-01T03:35:55.000Z","size":941,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-23T16:03:27.246Z","etag":null,"topics":["dom","dom-library","dom-manipulation","javascript","queryselector","template"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@jgarber/templatetemplate","language":"JavaScript","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/jgarber623.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2018-03-27T13:12:58.000Z","updated_at":"2025-01-03T01:38:16.000Z","dependencies_parsed_at":"2023-02-18T05:15:28.328Z","dependency_job_id":"93416a83-cada-4dec-8dd4-3706009640d2","html_url":"https://github.com/jgarber623/TemplateTemplate","commit_stats":{"total_commits":251,"total_committers":3,"mean_commits":83.66666666666667,"dds":0.4183266932270916,"last_synced_commit":"0d6143a1c2ceba3df8af7cb25b6ab3a00bed7de8"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgarber623%2FTemplateTemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgarber623%2FTemplateTemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgarber623%2FTemplateTemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgarber623%2FTemplateTemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jgarber623","download_url":"https://codeload.github.com/jgarber623/TemplateTemplate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241175750,"owners_count":19922569,"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":["dom","dom-library","dom-manipulation","javascript","queryselector","template"],"created_at":"2024-10-01T15:01:44.312Z","updated_at":"2025-10-22T21:22:52.981Z","avatar_url":"https://github.com/jgarber623.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!IMPORTANT]\n\u003e This project has moved to [codeberg.org/jgarber/TemplateTemplate](https://codeberg.org/jgarber/TemplateTemplate).\n\n# TemplateTemplate\n\n**A very small JavaScript `\u003ctemplate\u003e` manipulation library.**\n\n[![npm](https://img.shields.io/npm/v/@jgarber/templatetemplate.svg?logo=npm\u0026style=for-the-badge)](https://www.npmjs.com/package/@jgarber/templatetemplate)\n[![Downloads](https://img.shields.io/npm/dt/@jgarber/templatetemplate.svg?logo=npm\u0026style=for-the-badge)](https://www.npmjs.com/package/@jgarber/templatetemplate)\n[![Build](https://img.shields.io/github/actions/workflow/status/jgarber623/TemplateTemplate/ci.yml?branch=main\u0026logo=github\u0026style=for-the-badge)](https://github.com/jgarber623/TemplateTemplate/actions/workflows/ci.yml)\n\n\u003e [!NOTE]\n\u003e TemplateTemplate is feature complete and will only be updated to address bugs or security issues.\n\n### Key Features\n\n- Uses established Web standards (e.g. `\u003ctemplate\u003e`, `document.querySelector`)\n- Dependency-free\n- JavaScript module (ESM)\n\n## Getting TemplateTemplate\n\nYou've got a couple options for adding TemplateTemplate to your project:\n\n- [Download a release](https://github.com/jgarber623/TemplateTemplate/releases) from GitHub and do it yourself _(old school)_.\n- Install using [npm](https://www.npmjs.com/package/@jgarber/templatetemplate): `npm install @jgarber/templatetemplate --save`\n- Install using [Yarn](https://yarnpkg.com/en/package/@jgarber/templatetemplate): `yarn add @jgarber/templatetemplate`\n\n## Usage\n\nTemplateTemplate takes two arguments: a reference to a `\u003ctemplate\u003e` element and an object of `insertions` defining the content to insert into the `\u003ctemplate\u003e`.\n\n### Basic Example\n\nA basic example, inserting a row into a `\u003ctable\u003e`:\n\n```html\n\u003ctable id=\"projects\"\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth scope=\"col\"\u003eName\u003c/th\u003e\n      \u003cth scope=\"col\"\u003eAuthor\u003c/th\u003e\n      \u003cth scope=\"col\"\u003eURL\u003c/th\u003e\n      \u003cth scope=\"col\"\u003eLanguages\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003ctemplate id=\"row-template\"\u003e\n  \u003ctr\u003e\n    \u003cth class=\"name\" scope=\"row\"\u003e\u003c/th\u003e\n    \u003ctd class=\"author\"\u003e\u003c/td\u003e\n    \u003ctd class=\"url\"\u003e\u003c/td\u003e\n    \u003ctd class=\"languages\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/template\u003e\n\n\u003cscript type=\"module\"\u003e\n  import TemplateTemplate from \"@jgarber/templatetemplate\";\n\n  const tbody = document.querySelector(\"#projects tbody\");\n\n  const emptyTemplate = document.querySelector(\"#row-template\");\n\n  const insertions = {\n    \".name\": \"TemplateTemplate\",\n    \".author\": \"Jason Garber\",\n    \".url\": \"https://github.com/jgarber623/TemplateTemplate\",\n    \".languages\": \"JavaScript\",\n  };\n\n  const renderedTemplate = TemplateTemplate(emptyTemplate, insertions);\n\n  tbody.appendChild(renderedTemplate);\n\u003c/script\u003e\n```\n\nIn the example above, a reference to the `\u003ctemplate\u003e` element is passed to TemplateTemplate using [`document.querySelector`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector). The `insertions` argument an object whose keys (e.g. `'.name'`) are valid [CSS selectors](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) and whose values (e.g. `'TemplateTemplate'`) are strings of text to insert into the selected node.\n\n### Advanced Example\n\nA more complex example, inserting a row into a `\u003ctable\u003e` with different types of insertions.\n\n```html\n\u003ctable id=\"projects\"\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth scope=\"col\"\u003eName\u003c/th\u003e\n      \u003cth scope=\"col\"\u003eAuthor\u003c/th\u003e\n      \u003cth scope=\"col\"\u003eURL\u003c/th\u003e\n      \u003cth scope=\"col\"\u003eLanguages\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003ctemplate id=\"row-template\"\u003e\n  \u003ctr\u003e\n    \u003cth class=\"name\" scope=\"row\"\u003e\u003c/th\u003e\n    \u003ctd class=\"author\"\u003e\u003c/td\u003e\n    \u003ctd class=\"url\"\u003e\u003c/td\u003e\n    \u003ctd class=\"languages\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/template\u003e\n\n\u003ctemplate id=\"anchor-template\"\u003e\n  \u003ca\u003e\u003c/a\u003e\n\u003c/template\u003e\n\n\u003cscript type=\"module\"\u003e\n  import TemplateTemplate from \"@jgarber/templatetemplate\";\n\n  const tbody = document.querySelector(\"#projects tbody\");\n\n  const anchor = document.createElement(\"a\");\n\n  anchor.setAttribute(\"href\", \"https://sixtwothree.org\");\n  anchor.textContent = \"Jason Garber\";\n\n  tbody.appendChild(\n    TemplateTemplate(\"#row-template\", {\n      \"tr\": [null, {\n        \"class\": \"project\",\n        \"id\": \"project-cashcash\",\n      }],\n      \"th\": \"CashCash\",\n      \"th + td\": anchor,\n      \".url\": [\"https://github.com/jgarber623/CashCash\", {\n        \"style\": \"font-style: italic;\",\n      }],\n      \"td:last-child\": TemplateTemplate(\"#anchor-template\", {\n        \"a\": [\"JavaScript\", {\n          \"href\": \"https://github.com/search?q=language%3AJavaScript\",\n          \"target\": \"_blank\",\n        }],\n      }),\n    }),\n  );\n\u003c/script\u003e\n```\n\nThe example above demonstrates a handful of additional features that you may find useful. Let's break it down with a commented version of the most interesting bits:\n\n```js\n// The first argument to TemplateTemplate may also be a valid CSS selector.\nTemplateTemplate(\"#row-template\", {\n  // When an array is passed as a value, TemplateTemplate will use the first\n  // index in the array as the `textContent` for the node. If this value is\n  // `null`, TemplateTemplate skips setting the node's `textContent`.\n  //\n  // The second index is an object whose properties are added to the node as\n  // HTML attributes.\n  \"tr\": [null, {\n    \"class\": 'project',\n    \"id\": 'project-cashcash',\n  }],\n\n  \"th\": 'CashCash',\n\n  // TemplateTemplate will use `appendChild` when given an instance of a\n  // `DocumentFragment` or an `HTMLElement`.\n  \"th + td\": anchor,\n\n  \".url\": [\"https://github.com/jgarber623/CashCash\", {\n    \"style\": \"font-weight: bold;\",\n  }],\n\n  // TemplateTemplate may also be used to generate content from another\n  // `\u003ctemplate\u003e` and reuse it on the fly!\n  \"td:last-child\": TemplateTemplate(\"#anchor-template\", {\n    \"a\": [\"JavaScript\", {\n      \"href\": \"https://github.com/search?q=language%3AJavaScript\",\n      \"target\": \"_blank\",\n    }],\n  }),\n})\n```\n\n### Examples\n\nFor a full-featured TemplateTemplate demonstration, check out [the demo page](https://jgarber623.github.io/TemplateTemplate/example/) and [the example file](https://github.com/jgarber623/TemplateTemplate/blob/main/example/index.html).\n\n## Browser Support\n\n**TemplateTemplate works in modern browsers.** The library makes use of several new(ish) JavaScript features and, in an effort to remain as lightweight and dependency-free as possible, leaves it up to you to choose whether or not to polyfill features for older browsers.\n\n## Acknowledgments\n\nTemplateTemplate is written and maintained by [Jason Garber](https://sixtwothree.org) and is another in a growing collection of small, curiously-named JavaScript utilities:\n\n- [CashCash](https://github.com/jgarber623/CashCash), a very small DOM library inspired by [jQuery](https://jquery.com).\n- [RadioRadio](https://github.com/jgarber623/RadioRadio), a very small [PubSub](https://en.wikipedia.org/wiki/Publish–subscribe_pattern) library.\n- [RouterRouter](https://github.com/jgarber623/RouterRouter), a very small routing library extracted from [Backbone's Router](http://backbonejs.org/docs/backbone.html#section-185).\n\n## License\n\nTemplateTemplate is freely available under the [MIT License](https://opensource.org/licenses/MIT). Use it, learn from it, fork it, improve it, change it, tailor it to your needs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgarber623%2Ftemplatetemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjgarber623%2Ftemplatetemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgarber623%2Ftemplatetemplate/lists"}