{"id":19601851,"url":"https://github.com/frctl/consolidate","last_synced_at":"2025-04-27T17:32:03.489Z","repository":{"id":57112885,"uuid":"49659449","full_name":"frctl/consolidate","owner":"frctl","description":"[DEPRECATED] Generic template engine handler for Fractal, powered by consolidate.js.","archived":false,"fork":false,"pushed_at":"2018-11-28T09:30:36.000Z","size":19,"stargazers_count":4,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-21T01:28:44.347Z","etag":null,"topics":["deprecated"],"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/frctl.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","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":"2016-01-14T16:25:51.000Z","updated_at":"2020-06-12T23:53:39.000Z","dependencies_parsed_at":"2022-08-21T03:40:28.897Z","dependency_job_id":null,"html_url":"https://github.com/frctl/consolidate","commit_stats":null,"previous_names":["frctl/consolidate-adapter","frctl/consolidate-engine"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frctl%2Fconsolidate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frctl%2Fconsolidate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frctl%2Fconsolidate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frctl%2Fconsolidate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frctl","download_url":"https://codeload.github.com/frctl/consolidate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250806400,"owners_count":21490308,"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":["deprecated"],"created_at":"2024-11-11T09:20:28.276Z","updated_at":"2025-04-27T17:32:03.459Z","avatar_url":"https://github.com/frctl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Consolidate Adapter\n\nGeneric template engine adapter for [Fractal](http://frctl.github.io), powered by [consolidate.js](https://github.com/tj/consolidate.js).\n\n[![NPM Version](https://img.shields.io/npm/v/@frctl/consolidate.svg?style=flat-square)](https://www.npmjs.com/package/@frctl/consolidate)\n\nIf a specific Fractal template engine adapter for your desired language is available then it is recommended to **use that instead** as it will likely be easier to use and configure than this generic handler.\n\nCurrently specific template engine adapters have been implemented for:\n\n* [Handlebars](https://github.com/frctl/handlebars)\n* [Nunjucks](https://github.com/frctl/nunjucks)\n* [Mustache](https://github.com/frctl/mustache)\n\n\u003e Note: Due to the way that Consolidate handles loading of templates, this engine cannot be used for rendering pages, only components.\n\n## Usage\n\n#### 1. Install the consolidate engine adapter\n\n```shell\nnpm i @frctl/consolidate --save\n```\n\n#### 2. Install the template language parser\n\nAs an example, to use [Swig templates](http://paularmstrong.github.io/swig/), first you need to install Swig:\n\n```shell\nnpm i swig --save\n```\n\n#### 2. Add configuration details\n\nYou then need to configure Fractal to use Swig via the Consolidate adapter:\n\n```js\n\nconst consolidate = require('@frctl/consolidate');\nconst swigAdapter = consolidate('swig');\n\nfractal.components.engine(swigAdapter);  // use the consolidate/swig adapter\n\nfractal.components.set('ext', '.swig'); // look for files with a .swig file extension\n```\n\nYou can see a full list of supported template languages on the [Consolidate documentation](https://github.com/tj/consolidate.js).\n\n## Template Engine Instances\n\nYou can customise the [template engine instance](https://github.com/tj/consolidate.js#template-engine-instances) once it has been if you want to add filters, globals, mixins etc.\n\nFor example, to extend the above example to use a customised instance of Swig you could do the following:\n\n```js\nconst swig        = require('swig');\nconst consolidate = require('@frctl/consolidate');\n\n// Add a custom Swig filter\nswig.setFilter('join', function (input, char) {\n    return input.join(char);\n});\n\nconst swigAdapter = consolidate('swig', swig); // pass in the customised swig instance to use instead of the default one\n\nfractal.components.engine(swigAdapter); // set it to use as the template engine for components\n\nfractal.components.set('ext', '.swig');\n```\n\n## Special variables\n\nThe Consolidate adapter also makes a few special variables available to your templates. They all have names prefixed with an underscore to help prevent clashes with any context data variables that are set by the user.\n\nNote that using these may tie your templates a little more tightly into Fractal so you may choose not to use them for that reason.\n\nThe actual syntax for accessing these variables will depend on the template engine that you use - **Handlebars style** variables are shown in the examples below.\n\n### _config\n\nContains the full Fractal configuration object. Useful for when you want to refer to a configuration item in your documentation (or components).\n\n```html\n{{ _config.project.title }} \u003c!-- outputs the project title --\u003e\n{{ _config.components.ext }} \u003c!-- outputs the extension used for components --\u003e\n```\n\n### _self\n\nContains a simple data object representation of the top-level item (i.e. component or page) being rendered.\n\n```html\n{{ _self.title }} \u003c!-- outputs 'Button' --\u003e\n```\n\n### _target\n\nThis variable is only set in component preview layouts, and contains a simple data object representation of the item (i.e. component or page) being rendered _within_ the preview layout.\n\n```html\n{{ _target.title }} \u003c!-- outputs 'Button' --\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrctl%2Fconsolidate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrctl%2Fconsolidate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrctl%2Fconsolidate/lists"}