{"id":21980414,"url":"https://github.com/billykong/simple-templating-engine","last_synced_at":"2025-03-23T01:14:51.056Z","repository":{"id":32601261,"uuid":"137304181","full_name":"billykong/simple-templating-engine","owner":"billykong","description":"A simple template engine which you can customise with a handler function","archived":false,"fork":false,"pushed_at":"2022-12-30T20:16:47.000Z","size":255,"stargazers_count":2,"open_issues_count":11,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T04:28:18.961Z","etag":null,"topics":["js-template","json-template","template","template-engine"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/simple-template-engine","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/billykong.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}},"created_at":"2018-06-14T04:00:19.000Z","updated_at":"2023-02-18T07:01:41.000Z","dependencies_parsed_at":"2023-01-14T21:42:07.792Z","dependency_job_id":null,"html_url":"https://github.com/billykong/simple-templating-engine","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billykong%2Fsimple-templating-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billykong%2Fsimple-templating-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billykong%2Fsimple-templating-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billykong%2Fsimple-templating-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/billykong","download_url":"https://codeload.github.com/billykong/simple-templating-engine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245040691,"owners_count":20551308,"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":["js-template","json-template","template","template-engine"],"created_at":"2024-11-29T17:11:11.741Z","updated_at":"2025-03-23T01:14:51.033Z","avatar_url":"https://github.com/billykong.png","language":"JavaScript","readme":"[![Build Status](https://travis-ci.org/billykong/simple-templating-engine.svg?branch=master)](https://travis-ci.org/billykong/simple-templating-engine)\n[![Coverage Status](https://coveralls.io/repos/github/billykong/simple-templating-engine/badge.svg?branch=master)](https://coveralls.io/github/billykong/simple-templating-engine?branch=master)\n[![npm version](https://img.shields.io/npm/v/simple-template-engine)](https://img.shields.io/npm/v/simple-template-engine)\n[![Run on Repl.it](https://repl.it/badge/github/billykong/simple-templating-engine)](https://repl.it/github/billykong/simple-templating-engine)\n\n# Simple Template Engine\n\n## Usage\n\n```JavaScript\nvar templeteEngine = require('./simple_templating_engine.js');\nvar template = \"Hello, \u003c% change_me %\u003e\";\nvar handlerWorld = function(key) { return { '\u003c% change_me %\u003e': 'World' } };\n\ntempleteEngine.populate(template, handlerWorld).then(populated =\u003e {\n    console.log(populated); // \"Hello, World\"\n});\n\nvar handlerAsyncWorld = function(key) { return { '\u003c% change_me %\u003e': 'Async World' } };\n(async function() {\n  let populated = await templeteEngine.populate(template, handlerAsyncWorld);\n  console.log(populated); // Hello, Async World\n})();\n\n```\n\nIt also work with JSON template:\n```JavaScript\nvar templateJSON = `{ \"root\": \u003c% change_me %\u003e }`;\nvar handlerJSON = function(key) { \n  return { \n    '\u003c% change_me %\u003e': { \n      'key1': 'value1',\n      'key2': 'value2'\n    } \n  } \n};\n\ntempleteEngine.populate(templateJSON, handlerJSON).then(populated =\u003e {\n    console.log(JSON.parse(populated)); \n    // { \"root\": {\"key1\":\"value1\",\"key2\":\"value2\"} }\n});\n```\n\nThe handler can be an async function when we need to call remote APIs to get data:\n```JavaScript\nvar handlerJSON = async function(key) { \n  return await {\n    '\u003c% change_me %\u003e': { \n      'key1': 'value1',\n      'key2': 'value2'\n    } \n  } \n};\ntempleteEngine.populate(templateJSON, handlerJSON).then(populated =\u003e {\n    console.log(populated); \n});\n```\n\nYou can also use another matcher pattern other than `\u003c% ... %\u003e`:\n```JavaScript\nvar template = \"Hello, {_ change_me _}\";\nvar options = { matcher: /\"{_([^%\u003e]+)?_}\"/g}\nvar handler = function(key) { return { '{_ change_me _}': 'World' } };\n\ntempleteEngine.populate(template, handler, options).then(populated =\u003e {\n    console.log(populated); // \"Hello, World\"\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbillykong%2Fsimple-templating-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbillykong%2Fsimple-templating-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbillykong%2Fsimple-templating-engine/lists"}