Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (72 sloc) 2.69 KB
<!DOCTYPE html>
<title>Products Using Custom LoDash Plug-in for Sammy</title>
<li><a href="#/">Home</a></li>
<li><a href="#/products">Products</a></li>
<li><a href="#/products/1">Product 1</a></li>
<li><a href="#/data">Data</a></li>
<div id='content'></div>
<script src="Scripts/jquery-1.9.1.js"></script>
<script src="Scripts/lodash.js"></script>
<script src="Scripts/sammy-0.7.4.js"></script>
<script src="Scripts/sammy.lodash.js"></script>
(function () {
"use strict";
console.log("initializing sammy");
var app = $.sammy('#content', function () {
// first param is a function name
this.use('LoDash', 'html');
// the callback is the entire route wrapped in a closure
this.around(function (callback) {
var context = this;
this.load('data/3-products.txt', { json: true })
.then(function (items) {
context.items = items;
this.get('#/', function (context) {
context.log('Yo yo yo');''); // clear the content area before loading the partials
context.$element().append('<h1>Main page</h1>');
this.get('#/data', function (context) {''); // clear the content area before loading the partials
this.get('#/products/:id', function (context) {
var param = context.params['id'];
var products = context.items.products
// find the product based on the value of :id
var productData = _.find(products, function (product) {
return === param;
if (!productData) {
return context.notFound();
// partial() internally calls render and swap
// creates the html and puts it into $element
context.partial('Templates/4-product.html', { product: productData });
this.get('#/products', function (context) {
var products = context.items;''); // clear out the $element in this case '#content'
context.render('templates/4-products.html', products)
$(function () {'#/');
You can’t perform that action at this time.