{"id":21871733,"url":"https://github.com/ericmorand/gulp-twing","last_synced_at":"2025-06-12T22:33:21.909Z","repository":{"id":54659301,"uuid":"124223110","full_name":"ericmorand/gulp-twing","owner":"ericmorand","description":"Compile Twig templates with Gulp. Built upon Twing.","archived":false,"fork":false,"pushed_at":"2021-02-05T10:09:20.000Z","size":86,"stargazers_count":8,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T07:16:48.490Z","etag":null,"topics":["gulp","gulplugin","twig"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericmorand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-07T11:01:14.000Z","updated_at":"2023-04-19T12:53:10.000Z","dependencies_parsed_at":"2022-08-13T23:10:13.624Z","dependency_job_id":null,"html_url":"https://github.com/ericmorand/gulp-twing","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmorand%2Fgulp-twing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmorand%2Fgulp-twing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmorand%2Fgulp-twing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmorand%2Fgulp-twing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericmorand","download_url":"https://codeload.github.com/ericmorand/gulp-twing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248852184,"owners_count":21171843,"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":["gulp","gulplugin","twig"],"created_at":"2024-11-28T06:15:06.536Z","updated_at":"2025-04-14T23:56:01.704Z","avatar_url":"https://github.com/ericmorand.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-twing\n\n[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage percentage][coveralls-image]][coveralls-url]\n\nCompile [Twig](https://github.com/twigphp/Twig) templates with [gulp](https://github.com/gulpjs/gulp). Build upon [Twing](https://github.com/ericmorand/twing).\n\n## Prerequisites\n\n* Requires [Node.js](https://github.com/nodejs/node) ≥ 8.0.0\n* Requires [Twing](https://www.npmjs.com/package/twing) ≥ 5.0.2\n\n## Installation\n\n```bash\nnpm install twing gulp-twing --save\n```\n\n## Usage\n\n`var twing = require('gulp-twing');`\n\n### twing(env, data = {}, options = {})\n\nReturn an object transform stream that expects entry filenames.\n\n* env\n\n  A [TwingEnvironment](https://ericmorand.github.io/twing/api.html#basics) instance.\n\n* data\n\n  A hash of data passed to the render function of the template. See [Twing documentation](https://ericmorand.github.io/twing/api.html#rendering-templates) for details.\n\n* options\n\n  An optional hash of options. The following options are supported:\n\n  * outputExt\n\n    The output file extension including the `.`. Defaults to `.html`.\n\n  * templatePaths\n\n    A path string or an array of path strings to pass to [TwingLoaderFilesystem](https://ericmorand.github.io/twing/api.html#twingloaderfilesystem). Defaults to ` '.'`.\n\n### Examples\n\nThe following examples all require importing gulp, gulp-twing and instantiating a Twing environment:\n\n```javascript\n// top of gulpfile.js\nvar gulp = require('gulp');\nvar twing = require('gulp-twing');\nvar {TwingEnvironment, TwingLoaderRelativeFilesystem} = require('twing');\n\nlet env = new TwingEnvironment(new TwingLoaderRelativeFilesystem());\n```\n\n#### Basic usage\n\nTo compile all `.twig` files in the source directory `src/` saving the output as `.html` in the destination directory `dest/`, use\n\n```javascript\n// in gulpfile.js\nfunction twig() {    \n    return gulp.src('src/**/*.twig')\n        .pipe(twing(env))\n        .pipe(gulp.dest('dest'))\n}\n```\n\n#### CLI usage\n\nTo expose the above function to the command line in gulp 3 or gulp 4, use `gulp.task`:\n\n```javascript\n// in twig()\ngulp.task('twig', twig);\n```\n\nCall the function with the command `gulp twing`.\n\nIf you don't need to support gulp 3, you can use the more terse gulp 4 syntax\n\n```javascript\n// in twig()\ngulp.task(twig);\n```\n\n#### Classic gulp syntax\n\nIt may be convenient to use the classic syntax, for example when migrating an older gulp project's Twig compilation to Twing. This is not recommended for new projects as it is not supported by gulp 4.\n\n```javascript\n// in gulpfile.js\ngulp.task('twig', function() {\n    return gulp.src('src/**/*.twig')\n        .pipe(twing(env))\n        .pipe(gulp.dest('dest'))\n});\n```\n\n#### Passing data\n\nYou can pass data to Twig templates during compilation with the gulp-twing's data hash.\n\nFor example, to compile the template\n\n```twig\n{# src/example.twig #}\n{{ foo }}\n```\n\nto\n\n```html\n\u003c!-- dest/example.twig --\u003e\nbar\n```\n\nuse\n\n```javascript\n// in gulpfile.js\nfunction twig() {\n    return gulp.src('src/**/*.twig')\n        .pipe(twing(env, {foo: 'bar'}))\n        .pipe(gulp.dest('dest'))\n}\n```\n\n#### Renaming files\n\nBy default, gulp-twing appends `.html` to compiled files. Changing this behavior is easy.\n\n##### Strictly named templates\n\nUse gulp-twing's `outputExt` option when applying the same file extension change to all source files. For example, use `outputExt: '.ext'` to compile example.twig as example.ext. Or use `outputExt: ''` to compile example.ext.twig as example.ext.\n\n```javascript\n// in gulpfile.js\n\n// src contains only *.css.twig and *.html.twig templates\n\nfunction twig() {\n    return gulp.src('src/**/*.twig')\n        .pipe(twing(env, {}, {outputExt: ''}))\n        .pipe(gulp.dest('dest'))\n}\n\n// dest will contain *.css and *.html files\n```\n\n#### Loosely named templates\n\nIf you need more control on the name of the ouput, use [gulp-rename](https://www.npmjs.com/package/gulp-rename).\n\nTo compile index.css.twig, index.html.twig, and foo.twig saving the output to index.css, index.html, and foo.html, use\n\n```javascript\n// in gulpfile.js\nvar rename = require('gulp-rename');\n\n// src contains foo.twig, index.css.twig and index.html.twig\n\nfunction twig() {\n    gulp.src('src/**/*.twig')\n        .pipe(twing(env))\n        .pipe(rename(function(path) {\n            if (path.basename.indexOf('.') \u003e -1) {\n                path.extname = '';\n            }\n        }))\n        .pipe(gulp.dest('dest'))\n}\n\n// dest will contain foo.html, index.css and index.html\n```\n\nBy combining `gulp-rename` and `outputExt`, you can compile index.css.twig, index.html.twig, foo.twig saving the output to index.css, index.html, and foo.ext:\n\n```javascript\n// in gulpfile.js\nvar rename = require('gulp-rename');\n\n// src contains foo.twig, index.css.twig and index.html.twig\n\nfunction twig() {\n    gulp.src('src/**/*.twig')\n        .pipe(twing(env, {}, {outputExt: '.ext'}))\n        .pipe(rename(function(path) {\n            if (path.basename.indexOf('.') \u003e -1) {\n                path.extname = '';\n            }\n        }))\n        .pipe(gulp.dest('dest'))\n}\n\n// dest will contain foo.ext, index.css and index.html\n```\n\n## Contributing\n\n* Fork the main repository\n* Code\n* Implement tests using [node-tap](https://github.com/tapjs/node-tap)\n* Issue a pull request keeping in mind that all pull requests must reference an issue in the issue queue\n\n## License\n\nApache-2.0 © [Eric MORAND]()\n\n[npm-image]: https://badge.fury.io/js/gulp-twing.svg\n[npm-url]: https://npmjs.org/package/gulp-twing\n[travis-image]: https://travis-ci.org/ericmorand/gulp-twing.svg?branch=master\n[travis-url]: https://travis-ci.org/ericmorand/gulp-twing\n[coveralls-image]: https://coveralls.io/repos/github/ericmorand/gulp-twing/badge.svg\n[coveralls-url]: https://coveralls.io/github/ericmorand/gulp-twing","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericmorand%2Fgulp-twing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericmorand%2Fgulp-twing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericmorand%2Fgulp-twing/lists"}