GithubHelp home page GithubHelp logo

gulp-template's Introduction

gulp-template Build Status

Render/precompile Lo-Dash/Underscore templates

Issues with the output should be reported on the Lo-Dash issue tracker.

Install

$ npm install --save-dev gulp-template

Usage

src/greeting.html

<h1>Hello <%= name %></h1>

gulpfile.js

var gulp = require('gulp');
var template = require('gulp-template');

gulp.task('default', function () {
	return gulp.src('src/greeting.html')
		.pipe(template({name: 'Sindre'}))
		.pipe(gulp.dest('dist'));
});

You can alternatively use gulp-data to inject the data:

var gulp = require('gulp');
var template = require('gulp-template');
var data = require('gulp-data');

gulp.task('default', function () {
	return gulp.src('src/greeting.html')
		.pipe(data(function () {
			return {name: 'Sindre'};
		}))
		.pipe(template())
		.pipe(gulp.dest('dist'));
});

dist/greeting.html

<h1>Hello Sindre</h1>

API

template(data, [options])

Render a template using the provided data.

template.precompile([options])

Precompile a template for rendering dynamically at a later time.

data

Type: Object

The data object used to populate the text.

options

Type: Object

Lo-Dash _.template options.

Notes

If you use grunt instead of gulp, but want to perform a similar task, use grunt-template.

License

MIT © Sindre Sorhus

gulp-template's People

Contributors

sindresorhus avatar turbo87 avatar fodier avatar mathiasbynens avatar

Watchers

Yuval Netanel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.