{"id":14989670,"url":"https://github.com/connorwiseman/koa-hbs-renderer","last_synced_at":"2025-04-12T01:41:17.426Z","repository":{"id":143882752,"uuid":"88427759","full_name":"ConnorWiseman/koa-hbs-renderer","owner":"ConnorWiseman","description":"A Handlebars template renderer for Koa applications.","archived":false,"fork":false,"pushed_at":"2017-10-31T19:28:28.000Z","size":215,"stargazers_count":6,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T21:21:59.544Z","etag":null,"topics":["handlebars","koa","nodejs"],"latest_commit_sha":null,"homepage":"","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/ConnorWiseman.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":"2017-04-16T16:30:06.000Z","updated_at":"2020-09-24T22:38:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"797222d7-aa34-42b9-b88b-47f7275b72be","html_url":"https://github.com/ConnorWiseman/koa-hbs-renderer","commit_stats":{"total_commits":81,"total_committers":3,"mean_commits":27.0,"dds":0.06172839506172845,"last_synced_commit":"94cd84585543e157bda40bdbf27c2b4cc3e1ee58"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnorWiseman%2Fkoa-hbs-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnorWiseman%2Fkoa-hbs-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnorWiseman%2Fkoa-hbs-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnorWiseman%2Fkoa-hbs-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ConnorWiseman","download_url":"https://codeload.github.com/ConnorWiseman/koa-hbs-renderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505742,"owners_count":21115352,"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":["handlebars","koa","nodejs"],"created_at":"2024-09-24T14:18:44.327Z","updated_at":"2025-04-12T01:41:17.403Z","avatar_url":"https://github.com/ConnorWiseman.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-hbs-renderer\n\n[![npm](https://img.shields.io/npm/v/koa-hbs-renderer.svg?style=flat-square)](https://www.npmjs.com/package/koa-hbs-renderer)\n![Node.js](https://img.shields.io/badge/node.js-%3E=_7.6.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/ConnorWiseman/koa-hbs-renderer/master.svg?style=flat-square)](https://travis-ci.org/ConnorWiseman/koa-hbs-renderer) [![Coverage](https://img.shields.io/codecov/c/github/ConnorWiseman/koa-hbs-renderer.svg?style=flat-square)](https://codecov.io/gh/ConnorWiseman/koa-hbs-renderer)\n[![Dependencies Status](https://david-dm.org/ConnorWiseman/koa-hbs-renderer/status.svg?style=flat-square)](https://david-dm.org/ConnorWiseman/koa-hbs-renderer)\n[![devDependencies Status](https://david-dm.org/ConnorWiseman/koa-hbs-renderer/dev-status.svg?style=flat-square)](https://david-dm.org/ConnorWiseman/koa-hbs-renderer?type=dev)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/ConnorWiseman/koa-hbs-renderer/blob/master/LICENSE)\n\n\u003e A Handlebars template renderer for [Koa](https://github.com/koajs/koa) applications.\n\n\n## Installation\n\n```shell\nnpm install --save koa-hbs-renderer\n```\n\n\n## Usage\n### views/template.hbs\n```html\n\u003cp\u003eThis is a template. Isn't that {{adjective}}?\u003c/p\u003e\n```\n\n### index.js\n```javascript\nconst Koa      = require('koa');\nconst path     = require('path');\nconst renderer = require('koa-hbs-renderer');\n\nlet app = new Koa();\n\napp.use(renderer({\n  paths: {\n    views: path.join(__dirname, 'views')\n  }\n}));\n\napp.use(async (ctx, next) =\u003e {\n  await ctx.render('template', {\n    adjective: 'useful'\n  });\n});\n\napp.listen(3000);\n```\n\n## Options\n```javascript\nconst Handlebars = require('handlebars');\n\nlet options = {\n  cacheExpires:  60,\n  contentTag:    'content',\n  defaultLayout: 'default',\n  environment:   'development',\n  extension:     '.hbs',\n  hbs:           Handlebars.create(),\n  paths: {\n    views:    path.join(__dirname, 'views'),\n    layouts:  path.join(__dirname, 'layouts'),\n    partials: path.join(__dirname, 'partials'),\n    helpers:  path.join(__dirname, 'helpers')\n  },\n  Promise:      Promise\n};\n\napp.use(renderer(options));\n```\n\n### cacheExpires\nThe length of time, in seconds, to keep compiled Handlebars templates in the in-memory cache before recompilation. Defaults to `60`.\n\n### contentTag\nThe name of the block used by layouts to render views. Defaults to `content`, meaning views will be rendered onto layouts where `{{{content}}}` appears.\n\n### defaultLayout\nThe name of the layout to use by default if `paths.layouts` is defined. Defaults to `default`.\n\n### environment\nThe current Node.js environment, used to determine whether or not to invalidate the contents of cached templates. If set to `development`, cached templates will expire after the amount of time specified by [`cacheExpires`](#cacheexpires) above. Defaults to `process.env.NODE_ENV`.\n\n### extension\nThe file extension used by template files. Defaults to `.hbs`.\n\n### hbs\nA Handlebars environment to use. If one is not provided, one will be created via [`Handlebars.create`](http://handlebarsjs.com/reference.html#base-create) when the middleware function is called.\n\n### paths\nAn object literal of specified file paths. _Required._\n\n#### views\nThe path to a directory of view templates. _Required._\n\n#### partials\nThe path to a directory of partial templates. If specified, all templates in the partials directory will be compiled and cached together. _Optional._\n\n#### layouts\nThe path to a directory of layout templates. _Optional._\n\n#### helpers\nThe path to a directory of helper functions contained in JavaScript files. If specified, all functions in the helpers directory will be loaded and made available to the Handlebars environment for rendering. _Optional._\n\n### Promise\nThe constructor function to create internal Promises from. Defaults to the built-in `Promise` object; has been tested to work with [`bluebird`](https://github.com/petkaantonov/bluebird/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconnorwiseman%2Fkoa-hbs-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconnorwiseman%2Fkoa-hbs-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconnorwiseman%2Fkoa-hbs-renderer/lists"}