Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set custom context of the template? #642

Closed
ivadenis opened this issue Feb 3, 2014 · 1 comment
Closed

How to set custom context of the template? #642

ivadenis opened this issue Feb 3, 2014 · 1 comment

Comments

@ivadenis
Copy link

ivadenis commented Feb 3, 2014

I'm using 0.10.0, how do I set context of the template?
I've tried something like this, but context is being overwritten...

templates: {
        empty: function(query);
            var geo = $('input#city_selector').data('geo');
            var template = require('text!../../templates/vendor404.html');
            var html = Handlebars.compile(template);
            var data = { 'geo': geo, 'query': query };
            return html(data);
        }
@jharding
Copy link
Contributor

jharding commented Feb 4, 2014

The context the empty template gets called with is { query: 'the query' }, so you'd want to do something like:

var template = require('text!../../templates/vendor404.html');
var emptyTmpl = Handlebars.compile(template);

var empty = function(context) {
  var geo = $('input#city_selector').data('geo');
  var data = { 'geo': geo, 'query': context.query };

  return emptyTmpl(data);
}

// ...
templates: {
  empty: empty
}
// ...

@jharding jharding closed this as completed Feb 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants