Tuesday, 8 March 2011

SproutCore: Composite View Using HandleBars

Real MotoCycle:   Handlebars!
In Russia, we used to ride real motocycles.  Like dat one.  Now in SproutCore, handlebars is the way.  Alexei say it "the govno" but I don't think he say that right.

Note:  no oblong wheels on Russian motocycle! law l

Seriousness time now.  Comrade Topher in irc posted a gist showing how to implement the Handlebars with a CustomView.  He say.  Da, he right.  Works. Vodka time for him.

I say dis is future of SproutCore.  Write your Handlebars template using the hotmetal pro editor from 1996 and then fuse your Handlebars with the rest of your application.   Now you have true V8 motocycle power.



For your convenience here is Comrade Topher's codes.

<h1>Test Handlebars Page</h1>
<p>
  I really like {{ somevar }}!
</p>

MyApp.TestView = SC.ScrollView.extend({
  render: function(context) {
    // Note: Do not use the word 'view' as a key in the following data object,
    // as SproutCore and/or Handlebars will not display it properly
    // (probably because it's a helper function)
    var data = { somevar:"SproutCore" };
    var template = SC.TEMPLATES['test'](data);
    context.push( template );
  },
  update: function(jquery) {
    // do whatever you need to for somevar...
  }
});


No comments:

Post a Comment