How to access file data in ver 3.0
thecreation opened this issue · comments
Hi there,
In the v2.6.5, we can use options.data.root.file to access the file object on helper register callaback.
But in the new versions, it throw a error that file is not undefined.
(function() {
module.exports.register = function(Handlebars) {
var path = require('path');
Handlebars.registerHelper("file", function(options) {
var file = options.data.root.file;
return file.path;
});
};
}).call(this);
You need to specify the file
flag which is now false
by default.
gulp.src('...')
.pipe(hb({
file: true
}))
.pipe(gulp.dest('...'))
@amazingSurge You inspired a change. I dropped the { file: true }
flag and added a @file
property. In your example you'll access it like this:
Handlebars.registerHelper("file", function(options) {
var file = options.data.file;
return file.path;
});
In a template you'd access it like this (which does the same thing as your helper):
Release pending completion of CI tests.
Released as v5.0.0.
https://github.com/shannonmoeller/gulp-hb/tree/v5.0.0#-data-variables
Thank you! It works.