alanshaw / grunt-include-replace

Grunt task to include files and replace variables. Allows for parameterised includes.
MIT License
200 stars 45 forks source link

Missing include raw. #10

Closed FrankFang closed 11 years ago

FrankFang commented 11 years ago

There are some template file(contain <%= ... %> syntax) included into the index.html file. So I want to include raw data.

alanshaw commented 11 years ago

Currently you could do this by making the file an include and then using the processIncludeContents option to invoke grunt.template.process on the file contents. e.g.

Gruntfile.js

grunt.initConfig({
  includereplace: {
    processTemplate: {
      options: {
        foo: 'bar',
        processIncludeContents: function(contents, localVars) {
          return grunt.template.process(contents);
        }
      },
      src: 'test.html',
      dest: 'dist/'
    }
  }
});

test.html

@@include("include.html")

include.html

<p>A man walked into a <%= includereplace.processTemplate.options.foo %></p>

dist/test.html

<p>A man walked into a bar</p>