Reputation: 15692
I am building a Sammy application and I want to use Haml for it. Looks good so far.
app = $.sammy '#main', ->
@use 'Haml'
# Get some server data
$.getJSON '/some-data', (data) ->
# Hic sunt ponies
@get '#!/', ->
@partial '/tmpl/maintenance.haml'
@
$ -> app.run '#!/'
I have a template /tmpl/navbar.haml
that I would like to render before any routing. The reason for this is, the navbar is dependant on some data I receive from the server - again, before the routing.
So how can I render the template outside of the route? Sammy doesn't seem to have a method read for this, only inside a RenderContext
, e.g. a route.
Upvotes: 0
Views: 588
Reputation: 1217
I used 'location-changed' event, may be not ideal, but seems working:
this.bind('location-changed', function(context) {
var url = escape(app.getLocation());
if (app.connected()) {
$('#welcome').html(i18n('text_logged', 'index.php/account/account', app.connected().firstname, 'index.php/account/logout?_url=' + url));
} else {
$('#welcome').html(i18n('text_welcome', 'index.php/account/account?_url=' + url, 'index.php/account/register?_url=' + url));
}
});
Where app.connected is session check. And '#welcome' is outside of sammy's $element, and should be present.
You can use context.load for template.
Upvotes: 1