Async helper that prompts the user for a value and uses the answer as context for rendering the template.
npm install helper-ask> Async helper that prompts the user for a value and uses the answer as context for rendering the template.
Install with npm:
``sh`
$ npm install --save helper-ask
This helper can be used with the following applications:
* assemble
* verb
* update
* generate
* templates
This helper requires the base-questions plugin to be registered first. Uses the ask-when library to conditionally prompt the user. See that project for available options and additional API documentation.
`js
var ask = require('helper-ask');
var questions = require('base-questions');
var templates = require('templates');
var app = templates();
app.use(questions());
// register the helper, make sure to pass app to the function`
app.asyncHelper('ask', ask(app));
Example
If you're using templates directly, you'll need to create a collection and add a template engine.
`js`
app.create('pages');
app.engine('*', require('engine-base'));
app.option('engine', '*');
With the other apps you should be able to do the following:
`js
var page = app.page('foo', {content: '<%= ask("name") %>'});
app.option('askWhen', 'not-answered');
app.data('name', 'Brian');
app.render(page, function(err, view) {
if (err) return cb(err);
console.log(view.contents.toString());
//=> 'Brian'
cb();
});
`
Params
* app {Object}returns
* {Function}: Returns the helper function
Example
`html`
<%= ask('author.name') %>
* handlebars-helpers: More than 130 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate… more | homepage
* template-helpers: Generic JavaScript helpers that can be used with any template engine. Handlebars, Lo-Dash, Underscore, or… more | homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
_(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)_
To generate the readme and API documentation with verb:
`sh`
$ npm install -g verb verb-generate-readme && verb
Install dev dependencies:
`sh``
$ npm install -d && npm test
Jon Schlinkert
* github/jonschlinkert
* twitter/jonschlinkert
Copyright © 2016, Jon Schlinkert.
Released under the MIT license.
*
_This file was generated by verb-generate-readme, v0.1.31, on October 01, 2016._