shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.

Home Page:http://npm.im/gulp-hb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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):

{{@file.path}}

Release pending completion of CI tests.

Thank you! It works.