Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaswilburn/88547673c448815a9bdf to your computer and use it in GitHub Desktop.
Save thomaswilburn/88547673c448815a9bdf to your computer and use it in GitHub Desktop.
/*ROUTE CODE*/
server.route({
method:"GET",
path: "/books",
handler: function(request, reply){
fs.readFile("books.json", "utf8", function(err,data){
var links =[];
var list = JSON.parse(data);
reply.view("book-list", {
title: "Books",
//don't re-parse the data, just pass in the objetc
books: list.books
});
});
}
});
-------------
/*TEMPLATE CODE*/
<ul>
{{#each books}}
<li><a
{{! @key is a preset variable created by the #each helper }}
href="books/{{@key}} "
class="class-link">
{{! stop using `this`, it's not a good idea and you don't need it}}
{{name}}</a></li>
{{/each}}
</ul>
-----
/*JSON OBJECT*/
{
"books":{
"old_man_and_the_sea":{
"name":"The Old Man and the Sea",
"pages":"20",
"link":"old-man-and-the-sea",
"author": "Ernest Hemmingway",
"cover": "http://cdn8.openculture.com/wp-content/uploads/2014/07/old-man-and-the-sea-review.jpg"},
"ulysses":{
"name":"Ulysses",
"pages":"like 10 million",
"link":"ulysses",
"author": "James Joyce",
"cover": "http://upload.wikimedia.org/wikipedia/commons/a/ab/JoyceUlysses2.jpg"},
"frankenstein":{
"name":"Frankenstein",
"pages":"250",
"link":"frankenstein",
"author": "Mary Shelley",
"cover": "http://ciervoblanco.club/wp-content/uploads/2014/11/frankenstein-mary-shelley.jpg"},
"lord-jim":{
"name":"Lord Jim",
"pages":"400",
"link":"lord-jim",
"author": "Joseph Conrad",
"cover": "http://www.modernlib.com/authors/cAuthors/Conrad%20images/ConradJim35.big.jpg"}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment