{"id":14967729,"url":"https://github.com/doowb/layouts","last_synced_at":"2025-10-25T21:31:40.152Z","repository":{"id":19103935,"uuid":"22332384","full_name":"doowb/layouts","owner":"doowb","description":"Wraps templates with layouts. Layouts can use other layouts and be nested to any depth. This can be used 100% standalone to wrap any kind of file with banners, headers or footer content. Use for markdown, HTML, handlebars views, lo-dash templates, etc. Layouts can also be vinyl files.","archived":false,"fork":false,"pushed_at":"2019-04-11T15:35:19.000Z","size":207,"stargazers_count":28,"open_issues_count":1,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-31T10:36:12.288Z","etag":null,"topics":["consolidate","ejs","express","handlebars","jade","javascript","layout","layouts","liquid","nested-layouts","templates","vinyl","vinyl-files"],"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/doowb.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":"2014-07-28T05:54:34.000Z","updated_at":"2020-01-08T13:07:29.000Z","dependencies_parsed_at":"2022-08-25T15:51:57.947Z","dependency_job_id":null,"html_url":"https://github.com/doowb/layouts","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Flayouts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Flayouts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Flayouts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Flayouts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/layouts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238212407,"owners_count":19434955,"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":["consolidate","ejs","express","handlebars","jade","javascript","layout","layouts","liquid","nested-layouts","templates","vinyl","vinyl-files"],"created_at":"2024-09-24T13:38:31.618Z","updated_at":"2025-10-25T21:31:34.892Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# layouts [![NPM version](https://img.shields.io/npm/v/layouts.svg?style=flat)](https://www.npmjs.com/package/layouts) [![NPM monthly downloads](https://img.shields.io/npm/dm/layouts.svg?style=flat)](https://npmjs.org/package/layouts) [![NPM total downloads](https://img.shields.io/npm/dt/layouts.svg?style=flat)](https://npmjs.org/package/layouts) [![Linux Build Status](https://img.shields.io/travis/doowb/layouts.svg?style=flat\u0026label=Travis)](https://travis-ci.org/doowb/layouts)\n\n\u003e Wraps templates with layouts. Layouts can use other layouts and be nested to any depth. This can be used 100% standalone to wrap any kind of file with banners, headers or footer content. Use for markdown, HTML, handlebars views, lo-dash templates, etc. Layouts can also be vinyl files.\n\nPlease consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save layouts\n```\n\n## Usage\n\n```js\nconst renderLayouts = require('layouts');\n\nrenderLayouts(file, layoutCollection, options);\n```\n\n* `file` - a file object (or [vinyl](https://github.com/gulpjs/vinyl) file) with a `file.contents` property that must be a buffer\n* `layoutCollection` - an object of file objects to use as layouts\n* `options` - see [available options](#options)\n\n## Heads up!\n\nThis library does not clone the file object. If you want to prevent `file.contents` from being mutated (after rendering layouts), clone the file first before passing it to this library.\n\n## Example\n\n```js\nconst renderLayouts = require('layouts');\n\nconst file = {\n  contents: Buffer.from('\u003cdiv\u003eWrap me with a layout!!!\u003c/div\u003e'),\n  layout: 'one'\n};\n\nconst layoutCollection = {\n  one: { contents: Buffer.from('one before\\n{% body %}\\none after'), layout: 'two' },\n  two: { contents: Buffer.from('two before\\n{% body %}\\ntwo after') }\n};\n\nconst res = renderLayouts(file, layoutCollection);\nconsole.log(res.contents.toString());\n// two before\n// one before\n// \u003cdiv\u003eWrap me with a layout!!!\u003c/div\u003e\n// one after\n// two after\n```\n\n## Options\n\n### options.disableHistory\n\n**Type**: `boolean`\n\n**Default**: `undefined`\n\nBy default, layouts are prevented from being applied multiple times to the same string. Disable this by setting `disableHistory` to true.\n\n**Example**\n\n```js\nlayouts(file, layoutCollection, { disableHistory: true });\n```\n\n### options.layoutDelims\n\nCustom delimiters to use for injecting contents into layouts.\n\n**Type**: `regex`\n\n**Default**: `/{% (body) %}/g`\n\n### options.preserveWhitespace\n\nPreserve leading whitespace when injecting a string into a layout.\n\n**Type**: `boolean`\n\n**Default**: `undefined`\n\n## History\n\n### 1.0.0\n\n**Breaking changes**\n\n* renames `layoutHistory` to `layoutStack`\n* layouts in `layoutStack` are now the actual layout object, instead of the layout name\n\n**Added**\n\n* Adds support for a function as the last argument. If passed, the function is called on the file and each layout with this signature: `fn(file, layout)`.\n\n### 0.13.0\n\n**Breaking changes**\n\n* The main `layouts()` function now expects a `file` object as the first argument. This can be an object with `path`, `layout` and `contents` properties, or a valid [vinyl](https://github.com/gulpjs/vinyl) file. See the [API docs](#api) for more details.\n\n### 0.12.0\n\n**Breaking changes**\n\n* change `options.tag` to `options.contentTag`\n\n**Housekeeping**\n\n* update tests to use `assert` instead of `should`\n\n### 0.11.0\n\n* All view objects must now have a `path` property, following [vinyl](https://github.com/gulpjs/vinyl) conventions.\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble \"Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit\")\n* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates \"System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.\")\n* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb \"Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.\")\n\n### Contributors\n\n| **Commits** | **Contributor** |\n| --- | --- |\n| 151 | [jonschlinkert](https://github.com/jonschlinkert) |\n| 26  | [doowb](https://github.com/doowb) |\n\n### Author\n\n**Brian Woodward**\n\n* [GitHub Profile](https://github.com/doowb)\n* [Twitter Profile](https://twitter.com/doowb)\n* [LinkedIn Profile](https://linkedin.com/in/woodwardbrian)\n\n### License\n\nCopyright © 2019, [Brian Woodward](https://github.com/doowb).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 11, 2019._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Flayouts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Flayouts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Flayouts/lists"}