longshotlabs / meteor-template-extension

A Meteor package: Replace already defined templates, inherit helpers and events from other templates
https://atmospherejs.com/aldeed/template-extension
MIT License
220 stars 20 forks source link

Error: Template without a view #28

Closed lorensr closed 7 years ago

lorensr commented 9 years ago

When I add this package, v3.4.3, I get this error:

Exception in template helper: TypeError: Cannot read property 'name' of undefined
    at runTemplateHooks (http://localhost:3000/packages/aldeed_template-extension.js?2e25a48119980b3ff2fba34bcf67b18deac45199:412:72)
    at Object.templateExtensionMasterHook (http://localhost:3000/packages/aldeed_template-extension.js?2e25a48119980b3ff2fba34bcf67b18deac45199:364:5)
    at bindDataContext (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2786:16)
    at Blaze._wrapCatchingExceptions (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:1607:16)
    at http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2834:66
    at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:3382:12)
    at wrapHelper (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2833:27)
    at Spacebars.call (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:169:51)
    at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:109:25)
    at Object.Spacebars.mustache (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:113:39)
                              // 370
function runTemplateHooks(type, template, args) {                                                                   // 371
  var i, name = parseName(template.viewName) || parseName(template.view.name), h = templateHooks[type][name];       // 372

I guess that means one of my templates doesn't have a view? I can't imagine why.

aldeed commented 9 years ago

Not sure. Is this with Meteor 1.0.4+? We haven't tested and updated for the new Meteor release yet.

lorensr commented 9 years ago

yep,

$ m --version
Meteor 1.0.4.2
aldeed commented 9 years ago

@lorensr, I looked into this a bit and I can't reproduce, and all tests are passing with Meteor 1.0.4+. Can you link to a repo with a simple reproduction so we can figure out what's happening?

We do still need to update this pkg to play more nicely with the new onCreated/onRendered/onDestroyed, but I'm not sure if that's related to your issue.

lorensr commented 9 years ago

I can't reproduce, it's a large app, and I'm just adding the package, not calling anything. Looks like it would be fixed by checking if view is undefined before accessing the name

lorensr commented 9 years ago

Maybe something like this?

var i, name = parseName(template.viewName);
if (!name) {
  if (template.view) {
    name = parseName(template.view.name);
  } else {
    return;
  }
}
var h = templateHooks[type][name];  
markudevelop commented 9 years ago

@aldeed I get the same error I can reproduce it easily just try to invoke rendered Template.Name.rendered() in console. It will not work.

lorensr commented 9 years ago

That error occurs elsewhere in the package, but it does come from the same problem of template.view being undefined:

image

MasterAM commented 9 years ago

This happened to me when I was trying to send a data property called created as an argument to a template helper:

<span class="date">{{datetime created}}</span>

It then tried to run the template hooks, but got the data object instead of the template instance.

Changing the property name or removing the parameter resolves this.

lorensr commented 9 years ago

Wow. Thank you!!! Fixed it.

Before: {{days_ago created}}

After:

{{days_ago get_created}}
UI.registerHelper 'get_created', ->
  @created
aldeed commented 7 years ago

Closing. Pretty sure this was fixed awhile back.