I want to make home like this prototype:enter image description here
Here there are four section-hollywood, english ,spanish and italian movie For all to save movie data i have only one schema
var mongoose= require('mongoose');
var movies= mongoose.Schema({
title:String,
image:String,
genre:String,//can either hollywood,italian,english or spanish
description:{
type:String,trim:true
},
release:String,
download:String,
youtube:String,
upload:{
type: Date,
default: Date.now
}
});
var Movie=mongoose.model("movie",movies);
module.export
So to get for data from home page i have use this method which is not successful.If you have got any idea please how to do it?
In main route:
router.get('/',(req,res,next)=> {
//as i want only 4 hollywood movie to appear first in home page so use limit
var hollywood= Movie.find({genre:'hollywood'}).limit(4).sort('-upload').exec( function(err, hollywood) {
if (err)
console.log(err);
else
return hollywood;
});
var english= Movie.find({genre:'hollywood'}).limit(4).sort('-upload').exec( function(err, english) {
if (err)
console.log(err);
else
return english;
});
var spanish= Movie.find({genre:'hollywood'}).limit(4).sort('-upload').exec( function(err, spanish) {
if (err)
console.log(err);
else
return spanish;
});
var italian= Movie.find({'genre':'genre'}).limit(4).sort('-upload').exec( function(err, italian) {
if (err)
console.log(err);
else
return italian;
});
res.render('index.ejs',{hollywood:hollywood,english:english,spanish:spanish,italian:italian});
});
In index.ejs
<div class="row">
<% hollywood.forEach(function(movie){ %>
<div class="col-xs-12 col-sm-4 col-md-3 col-lg-3">
<div class="thumbnail">
<img src="<%=movie.image%>" alt="">
<div class="caption">
<h4><%=movie.title%>Movie Name</h4>
<p><a href="/detail/<%=movie._id%>" class="btn btn-primary" role="button">Download</a></p>
</div>
</div>
</div>
<%})%>
<div class="row">
<% english.forEach(function(movie){ %>
<div class="col-xs-12 col-sm-4 col-md-3 col-lg-3">
<div class="thumbnail">
<img src="<%=movie.image%>" alt="">
<div class="caption">
<h4><%=movie.title%>Movie Name</h4>
<p><a href="/detail/<%=movie._id%>" class="btn btn-primary" role="button">Download</a></p>
</div>
</div>
</div>
<%})%>
<div class="row">
<% spanish.forEach(function(movie){ %>
<div class="col-xs-12 col-sm-4 col-md-3 col-lg-3">
<div class="thumbnail">
<img src="<%=movie.image%>" alt="">
<div class="caption">
<h4><%=movie.title%>Movie Name</h4>
<p><a href="/detail/<%=movie._id%>" class="btn btn-primary" role="button">Download</a></p>
</div>
</div>
</div>
<%})%>
<div class="row">
<% italian.forEach(function(movie){ %>
<div class="col-xs-12 col-sm-4 col-md-3 col-lg-3">
<div class="thumbnail">
<img src="<%=movie.image%>" alt="">
<div class="caption">
<h4><%=movie.title%>Movie Name</h4>
<p><a href="/detail/<%=movie._id%>" class="btn btn-primary" role="button">Download</a></p>
</div>
</div>
</div>
<%})%>
via Sagar Rana Magar
No comments:
Post a Comment