Skip to content

Commit

Permalink
Modified index controller and template to present a list of products
Browse files Browse the repository at this point in the history
  • Loading branch information
lmarkus committed Dec 5, 2013
1 parent e9037fc commit 479a974
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
26 changes: 20 additions & 6 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
'use strict';

var Product = require('../models/productModel');

module.exports = function (server) {

/**
* Display a list of the products.
*/
server.get('/', function (req, res) {
var model = { name: 'kraken-example-shopping-cart' };

res.render('index', model);


Product.find(function (err, prods) {
if (err) {
console.log(err);
}

var model =
{
products: prods
};

res.render('index', model);

});

});

};
};
17 changes: 17 additions & 0 deletions public/templates/index.dust
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
<main role="main">
<p>{@pre type="content" key="index.greeting"/}</p>
<div class="products">
<ul class="nm-np inline">
{#products}
<li>
<form method="POST" action="cart">
<input type="hidden" name="item_id" value="{.id}">

<h3 class="nm-np">{.name}</h3>
<h4 class="nm-np">{.prettyPrice}</h4>
<input type="submit" value="{@pre type="content" key="index.addToCart"/}">
<!--If we don't add the Cross-Site Request Forgery token, this POST will be rejected-->
<input type="hidden" name="_csrf" value="{_csrf}">
</form>
</li>
{:else}
<li>There are no products :(<br>You should <a href="/products">add some</a></li>
{/products}
</ul>
</div>
</main>
{/body}

0 comments on commit 479a974

Please sign in to comment.