gulp-include-template
This is a gulp plugin to extend artTemplate include function replacing <% include() %> with compiled functions.
In 0.1.0 version, we add includeNative
to include native html but not compiled html. The syntax is the same with include
but without passing a data
object.
Usage
html/hello.html
<% var data = { "hello": "world" }; %><% include('header.html', data); %><% include('footer.html', data); %>
html/header.html
<%= hello %>
html/footer.html
<%= hello %>
var gulp = gulpIncludeTemplate = ; gulp;
After running the includeTemplate task:
compiled/hello.html
<% var data = { "hello": "world" }; %> <% (function($$data) {%> <% var hello=$$data.hello; %><%= hello %> <% })( data); %> <% (function($$data) {%> <% var hello=$$data.hello; %><%= hello %> <% })( data); %>
Set the base
If we want to refer to the js/css with the absolute url starts with '/', you should set the base attribute of gulp-include-template.
var gulp = gulpIncludeTemplate = ; // if we set the base of gulp-include-template, we can access them the absolute url starts with '/'gulpIncludeTemplate;gulp;
Html is like this.
<% var data = { "hello": "world" }; %><% include('/dirUnderPathToHtml/header.html', data); %><% include('/dirUnderPathToHtml/footer.html', data); %>
The compiled hello.html can be directly used by the artTemplate without loading the outer html in running time.
Release log
- 0.1.0 add
includeNative
to just include original content to template.