node.js - How do you display mongoose data in a pug template -


i exploring pug templates , have exporess/mongodb/mongoose backend.

the router index page meant display 'testimonials' , have following 'route':

const testimonial = require('../models/testimonial'); exports.index = (req, res) => {   testimonial.find((err, testimonials) => {     if (err) {       console.log("error: " + err);     } else {       res.render('home2', {         title: 'website',         testimonials: testimonials,       });     }   }); }; 

if add 'console.log' statement before render return testimonials in collection, data side works.

the index page includes 'partial' pug template testimonials following:

.nk-box.bg-gray-4   .nk-gap-4   .row     .nk-carousel-2(data-autoplay='12000', data-dots='true')       .nk-carousel-inner         each testimonial in testimonials           div             div               blockquote.nk-testimonial-3                 .nk-testimonial-photo(style="background-image: url('/images/avatar-man-2.jpg');")                 .nk-testimonial-body                   em                     | " testimonial.description "                 .nk-testimonial-name.h4 testimonial.createdby                 .nk-testimonial-source testimonial.modifieddate   .nk-gap-4 

the template creates correct number of testimonials data in each not being displayed. instead testimonial 'testimonial.description' instead of actual words, , 'testimonial.createdby' instead of person's name.

the template looping through being returned looks of it, cannot display data.

i'd appreciate guys can provide.

thanks again.

i think may need use #{} between variables interpolate values template

https://pugjs.org/language/interpolation.html

.nk-box.bg-gray-4   .nk-gap-4   .row     .nk-carousel-2(data-autoplay='12000', data-dots='true')       .nk-carousel-inner         each testimonial in testimonials           div             div               blockquote.nk-testimonial-3                 .nk-testimonial-photo(style="background-image: url('/images/avatar-man-2.jpg');")                 .nk-testimonial-body                   em                     | " #{testimonial.description} "                 .nk-testimonial-name.h4 #{testimonial.createdby}                 .nk-testimonial-source #{testimonial.modifieddate}   .nk-gap-4 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -