I m trying to show the selected option from the mongodb. I've tried to many times to solve this problem from checking different sources. i got this error ( Error: Missing helper: "select")
here is my handlebar_helper.js file
module.exports = (Handlebars)=>{
Handlebars.registerHelper('select', function(selected, options) {
return options.fn(this).replace(new RegExp('value = "'+ selected + '"'), '$&selected="selected"');
});
};
here is my main file app.js
const {select} = require('./helpers/handlebars_helpers');
app.engine('handlebars', exphbs({defaultLayout: 'home', helpers: {select: select}}));
app.set('view engine', 'handlebars');
here is edit.handlebars
{#select post.status}}
<option value="public">Public</option>
<option value="private">Private</option>
<option value="draft">Draft</option>
{{/select}}
See Question&Answers more detail:os