Search code examples
gruntjshandlebars.jsassemble

assemble - cannot use (register?) Handlebars helper


I am trying to create a very simple Handlebars helper

helpers/json.js

module.exports.json = function(obj) {
    return JSON.stringify(obj);
};

Gruntfile

module.exports = function(grunt) {

    grunt.initConfig({
        assemble: {
            options: {
                assets: "dist/assets",
                data: "src/data/*.json",
                layoutdir: "src/layouts/",
                partials: "src/partials/*.hbs",
                helpers: ["src/helpers/json.js"],
                flatten: true

            },

page.hbs

{{{#json  mydata.something }}}

But I get error when I try to use it

Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'INVALID' Use --force to continue.

If I make syntax mistakes in helpers/json.js I get an error about it, so it reads the file.


Solution

  • Looks like the correct syntax is

    {{{json mydata.something}}}
    

    Not it works.