2016-09-22 71 views
0

我正在探索PUG模板并拥有exporess/mongodb/mongoose后端。如何在pug模板中显示猫鼬数据

为索引页面的路由器是为了显示“推荐”和我有以下的“路线”:

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, 
     }); 
    } 
    }); 
}; 

如果我加上“的console.log”语句之前渲染它会返回集合中的所有推荐内容,因此数据面能够正常工作。

索引页包括用于与以下的一个推荐“部分”哈巴狗模板:

.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 

该模板创建推荐的正确数量,但不被显示在每个所述数据。相反,我通过'testimonial.Description'而不是实际的单词得到一个证言,'testimonial.CreatedBy'而不是这个人的名字。

模板正在循环通过它的外观返回的内容,我只是无法显示数据。

我非常感谢你们提供的帮助。

再次感谢。

回答

0

我想你可能需要使用变量之间的#{}与模板

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 
+0

法比奥你是个明星插值它的价值!谢谢。 – Pandafinity