Skip to content

Instantly share code, notes, and snippets.

@loginx
Created May 16, 2012 21:25
Show Gist options
  • Save loginx/2714068 to your computer and use it in GitHub Desktop.
Save loginx/2714068 to your computer and use it in GitHub Desktop.
Dynamic partials in Batman.js
<div data-replace="item">
PARTIAL 1: <span data-bind="item.name"></span>
</div>
<div data-replace="item">
PARTIAL 2: <span data-bind="item.name"></span>
</div>
class App.ItemsController extends App.ApplicationController
show: () ->
@render()
updatePartial: (node) ->
partial = $(node).val() || 'partial1'
v = new Batman.View
# This tells the View to use this file as its template
source: "items/_#{partial}"
# This feeds the controller's renderContext to the view.
context: @.get '_renderContext'
# If you want to use a string for the source instead of a filename, use this:
#html: "CUSTOM HTML: <div data-bind='item.name'></div>"
v.render()
<p>Main View</p>
<a data-event-click="updatePartial" data-id="partial1">Partial 1</a> |
<a data-event-click="updatePartial" data-id="partial2">Partial 2</a>
<div data-yield="item">
<div data-partial="items/_partial1"></div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment