mercredi 24 juin 2015

Equivalent of Ember.js (or Rails) yield in Sails.js w/Handlebars (SPA style)

So basically I want to do something that I can do in ember with handlebars but without using ember just sails.js and handlebars.

I set up sails project like so: sails new fooProject --template=handlebars after running npm install sails-generate-views-handlebars.

Great I have a layout file, all my files end in .handlebars woot.

But I would like to do something like this:

Views:

views/index.handlebars

{{>header}}
    {{yield}}
{{>footer}}

/views/partials/foo.handlebars

<div class="foo stuff">...</div>

Router:

config/routes.js

'/': {
    view: 'index',
    controller: 'FooController',
    action: 'index'
}

Controller:

controllers/FooController

index: function(req, res){
    return res.view({partials: 'partials/foo'}); // <-- I want foo partial in the yield.
}

So that I end up with this output:

<header>...</header>
    <div class="foo stuff">
<footer>...</footer>

Anytime my user navigates I'd like to render the new partial into that {{yield}} block without reloading the page. But that doesn't work, (I've tried). So how would I accomplish this?

To help clarify what I'm going for is a Single Page Application feel without having to use a front-end framework as well.




Aucun commentaire:

Enregistrer un commentaire