Reputation: 31
i cant get my saved data from my product seeder to the store correctly
it looks like this https://prnt.sc/t10v00
and i want the image and the titles from the data i have come to the page
and in my terminal says ///// Handlebars: Access has been denied to resolve the property "title" because it is not an "own property" of its parent
{{# each products}}
<div class="row">
{{# each this}}
<div class="col-sm-6 col-md-4">
<div class="thumbnail">
<img src="{{this.imagePath}}" alt="..." class = "img-responsive">
<div class="caption">
<h3 align="center">{{this.title}}</h3>
<p class="description">{{this.description}}</p>
<div class="clearfix">
<div class="price pull-left">€{{this.price}}<ahref="#" style="float:right"class="btn btn-primary pull-right" role="button">Add cart</a> </div>
</div>
</div>
</div>
{{/each}}
</div>
{{/each}}
index.js
var express = require('express');
var router = express.Router();
var Product = require('../models/product');
/* GET home page. */
router.get('/', function(req, res, next) {
Product.find(function(err, docs) {
var productChunks = [];
var chunkSize = 3;
for (var i = 0; i < docs.length; i += chunkSize) {
productChunks.push(docs.slice(i, i + chunkSize));
}
res.render('shop/index', { title: 'Shopping Cart', products: productChunks });
});
});
module.exports = router;
anyone can help me with that?
Upvotes: 1
Views: 1163
Reputation: 529
I've added the following code and it's working fine. You need to add the runtimeoptions here.
const {engine} = require('express-handlebars');
app.engine('.hbs', engine({
defaultLayout: 'main',
extname: 'hbs',
runtimeOptions: {
allowProtoPropertiesByDefault: true,
allowProtoMethodsByDefault: true
}
}));
app.set('view engine', '.hbs');
I have used the above code to implement the .hbs template engine.
Upvotes: 0
Reputation: 1
This code works for me:
const Handlebars = require('handlebars');
const expressHandlebars=require('express-handlebars');
const { allowInsecurePrototypeAccess } = require('@handlebars/allow-prototype-access');
// view engine setup
app.engine('.hbs', expressHandlebars({ handlebars: allowInsecurePrototypeAccess(Handlebars) ,defaultLayout: 'layout', extname: '.hbs'}));
//app.set('views', path.join(__dirname, 'views'));
app.set('view engine', '.hbs');
Upvotes: 0
Reputation: 11
"express-handlebars": "^3.0.0"
Used this version. It worked. It was giving same output for newer versions.
Upvotes: 1
Reputation: 1
Follow given bellow syntax:
dbName.find({}).lean()
// execute query
.exec(function(error, body) {
//Execute you code
});
Upvotes: 0