Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add {{partial}}

  • Loading branch information...
commit 015138ea569725811b43e0fd851dfd0c08446890 1 parent e72e2b7
@wycats wycats authored
View
19 packages/ember-handlebars/lib/helpers/template.js
@@ -47,3 +47,22 @@ Ember.Handlebars.registerHelper('template', function(name, options) {
Ember.TEMPLATES[name](this, { data: options.data });
});
+
+Ember.Handlebars.registerHelper('partial', function(name, options) {
+ var nameParts = name.split("/"),
+ lastPart = nameParts[nameParts.length - 1];
+
+ nameParts[nameParts.length - 1] = "_" + lastPart;
+
+ var underscoredName = nameParts.join("/");
+
+ var template = Ember.TEMPLATES[underscoredName],
+ deprecatedTemplate = Ember.TEMPLATES[name];
+
+ Ember.deprecate("You tried to render the partial " + name + ", which should be at '" + underscoredName + "', but Ember found '" + name + "'. Please use a leading underscore in your partials", template);
+ Ember.assert("Unable to find partial with name '"+name+"'.", template || deprecatedTemplate);
+
+ template = template || deprecatedTemplate;
+
+ template(this, { data: options.data });
+});
View
28 packages/ember-handlebars/tests/handlebars_test.js
@@ -2191,6 +2191,34 @@ test("should render other templates using the {{template}} helper", function() {
equal(Ember.$.trim(view.$().text()), "This sub-template is pretty great.");
});
+test("should render other templates using the {{partial}} helper", function() {
+ Ember.TEMPLATES._subTemplate = Ember.Handlebars.compile("sub-template");
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('This {{partial "subTemplate"}} is pretty great.')
+ });
+
+ Ember.run(function() {
+ view.appendTo('#qunit-fixture');
+ });
+
+ equal(Ember.$.trim(view.$().text()), "This sub-template is pretty great.");
+});
+
+test("should render other slash-separated templates using the {{partial}} helper", function() {
+ Ember.TEMPLATES["child/_subTemplate"] = Ember.Handlebars.compile("sub-template");
+
+ view = Ember.View.create({
+ template: Ember.Handlebars.compile('This {{partial "child/subTemplate"}} is pretty great.')
+ });
+
+ Ember.run(function() {
+ view.appendTo('#qunit-fixture');
+ });
+
+ equal(Ember.$.trim(view.$().text()), "This sub-template is pretty great.");
+});
+
test("should update bound values after the view is removed and then re-appended", function() {
view = Ember.View.create({
template: Ember.Handlebars.compile("{{#if view.showStuff}}{{view.boundValue}}{{else}}Not true.{{/if}}"),
Please sign in to comment.
Something went wrong with that request. Please try again.