Search code examples
javascriptassemble

Assemble string concat in template


I want to concat two strings inside a template, for example:

{{>
 masthead
 title=car-and.panel1.title
 image=  (imageBase "myimage.jpg")
 height="100"
}}

So I want to register a concat helper with assemble. None of the ways I've found in the docs seem to work though. I have a helper:

module.exports.register = function (Handlebars) {
  Handlebars.registerHelper("imageBase", (path) => "/images/" + path);
};

I am initialising the app with these options:

const app = assemble({
  ext: "html",
  helpers: ['./app/helpers/*.js' ]
});

I always get the error that it can't find the helper


Solution

  • It looks like you were looking at some of the grunt-assemble documentation and trying to apply that to the latest version of assemble. We're still working on getting all of that updated, but the assemble README is a good place to start for new documentation.

    Also, for the helpers specifically, that api is provided by templates and is documented here: https://github.com/jonschlinkert/templates#helper

    So to update your code example, you can do this to register the helper:

    const app = assemble();
    app.helper('imageBase', (path) => '/images/' + path);