Fork me on GitHub

THE SITE HAS MOVED TO Sammyjs.org. YOU ARE BEING REDIRECTED

Sammy

Documentation

FAQ

How can I use templates?

Currently you can render templates using ERB style notation.

<div id="mytemplate">
  <%= variable %>
</div>
<span class="x">&lt;div id=&quot;mytemplate&quot;&gt;</span>
<span class="x">  </span><span class="cp">&lt;%=</span> <span class="n">variable</span> <span class="cp">%&gt;</span><span class="x"></span>
<span class="x">&lt;/div&gt;</span>

Internally, Sammy uses a modified $.srender to do the parsing. Both template() and partial() use this method internally.
See the API for more details.

How do I load views from other files?

In an EventContext the partial() method can asynchronously load views and enact on the data, appending, replacing or parsing it.

Can I run multiple apps in the same document?

Yes! Each Sammy.Application is bound to a specific element and also has a unique ID and namespace. Since the whole Application is encapsulated in an object, the app can actually be passed around and modified during the course of a request.

You can also bind different applications to different elements on the page, basically creating ‘controllers’ for the individual elements. For example:

var menu = $.sammy(function() {
  
  element_selector = '#menu';
  
  get('#/', function() { ... //load the initial menu });
  
  get('#/:nav', function() { ...// show the subnav for :nav});
  
});

var main = $.sammy(function() {
  
  this.element_selector = '#main';
  
  this.get('#/', function() { ... //load the index });
  
  this.get('#/:nav', function() { ...// show the page coresponding to :nav});
  
});

$(function() {
  menu.run();
  main.run('#/');
});

With this pattern, you can separate the functionality for the menu and the main element, while responding to the exact same events.

I want Sammy to do X!

That’s awesome! Please feel free to fork the project on github and contact me if you have questions.