Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Carlos Sanchez
8,900 PointsHow to send values to templates with {{ variable }} tags?
I am implementing my own version of this project, and part of my own implementation is that I added a database to which i can connect and perform CRUD operations. Right now I am trying to print in one of the templates the data I am retrieving from the DB, however it does not seem to work as the page does not render anything, The data is good and not null since it prints the values when I do the print statement. Therefore I figure that the template is never receiving the data, what am I ding wrong? Its so much easier to do this part in NodeJS, why is the Handlebars iteration in java so much harder? :(
main.java
public class Main {
public static void main(String[] args) {
get("/", (req, res) -> "Hello");
get("/hello", (req, res) -> {
BookDAO bookTransfer = new BookDAO();
List<BookDTO> bookList = bookTransfer.readAll();
bookList.stream().forEach(System.out::println);
return new ModelAndView(bookList, "list.hbs");
}, new HandlebarsTemplateEngine());
}
}
list.hbs
1 Answer

Carlos Sanchez
8,900 PointsOk so I went back and rewatched the video again and came up with this fix:
public class Main {
public static void main(String[] args) {
get("/", (req, res) -> {
BookDAO bookTransfer = new BookDAO();
List<BookDTO> bookList = bookTransfer.readAll();
bookList.stream().forEach(System.out::println);
Map<String, Object> model = new HashMap<>();
model.put("books", bookList);
return new ModelAndView(model, "list.hbs");
}, new HandlebarsTemplateEngine());
}
}
base.hbs
list.hbs