2016-09-22 11 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 

テンプレートは、お客様の声の正確な数を作成しますが、それぞれのデータが表示されていない:

インデックスページには、以下と声のための「部分」パグテンプレートが含まれています。代わりに私は実際の言葉の代わりに「証言」を使って、証言を得て、その人の名前の代わりに「証言」を作成します。

テンプレートは見た目から返されているものをループしているため、データを表示できません。

私は確かにあなたが提供できる助けを感謝します。

もう一度おねがいします。

答えて

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

関連する問題