A simple blog application built with Backbone.js that connects to a backend API to display and manage blog posts.
blog-frontend/
├── index.html # Main HTML file with templates
├── app.js # Backbone.js application code (empty, ready for implementation)
├── styles.css # CSS styling for the blog
└── README.md # This file
The index.html file contains:
-
Main Container: A div with id
appthat holds the entire application -
Signposts: Empty divs that Backbone will populate:
#posts-container- Where the list of all blog posts will appear#post-detail-container- Where individual post details will show
-
JavaScript Templates: Script blocks with
type="text/template"that define how data should be displayed:<script type="text/template" id="post-list-item-template"> <div class="post-item"> <h2><%= title %></h2> </div> </script>
- The browser ignores these script blocks because it doesn't recognize "text/template" as executable JavaScript
- Your Backbone app can still access the HTML content using
document.getElementById()or jQuery - It's a clever way to store HTML templates in your HTML file without them rendering immediately
- Later, your JavaScript will grab these templates and use them to generate real HTML with actual data
- Uses Underscore.js template syntax (same as Ruby ERB, but processed by JavaScript)
<%= title %>gets replaced with actual data when the template is rendered- Example: If your API returns
{title: "My First Post"},<%= title %>becomes "My First Post"
The libraries are loaded in this specific order:
<script src="jquery-3.6.0.min.js"></script>
<script src="underscore.js"></script>
<script src="backbone.js"></script>
<script src="app.js"></script>- jQuery - Backbone uses jQuery for DOM manipulation and AJAX requests
- Underscore.js - Backbone depends on Underscore for:
- Template rendering (
_.template()) - Utility functions like
_.extend(),_.bind(), etc.
- Template rendering (
- Backbone.js - The main framework that depends on both jQuery and Underscore
- app.js - Your application code that uses all the above libraries
Important: If you load these in the wrong order, you'll get errors because each library depends on the previous ones being available.
Provides styling for:
- Dark background with white content container
- Post item styling with hover effects
- Post detail view styling
- Responsive design with max-width container
- ✅ HTML structure and templates are set up
- ✅ CSS styling is complete
- ✅ Library dependencies are included
- ⏳
app.jsis empty and ready for Backbone implementation
To make this blog functional, you'll need to implement in app.js:
- Backbone Model - Define what a blog post looks like
- Backbone Collection - Manage multiple blog posts and API communication
- Backbone Views - Handle rendering templates and user interactions
- Backbone Router - Handle navigation between list and detail views
This frontend is designed to connect to a backend API that should provide:
GET /posts- Return list of all blog postsGET /posts/:id- Return details for a specific post
The Backbone Collection will handle fetching data from your API and the Views will render it using the templates defined in index.html.# backbone-front