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

Template instance custom properties inaccessible inside content blocks #3540

Closed
rclai opened this issue Jan 23, 2015 · 22 comments
Closed

Template instance custom properties inaccessible inside content blocks #3540

rclai opened this issue Jan 23, 2015 · 22 comments

Comments

@rclai
Copy link

rclai commented Jan 23, 2015

Reproduction here: https://github.com/rclai/meteor-template-instance-issue

@rclai rclai changed the title Template instance custom properties inaccessible Template instance custom properties inaccessible inside content blocks Jan 23, 2015
@stubailo
Copy link
Contributor

Great reproduction!

@stubailo
Copy link
Contributor

In PR #3545

@rclai
Copy link
Author

rclai commented Jan 23, 2015

Cool.

There is another issue I'm going to submit regarding Template.parentData() returning the wrong stuff. Like for example, parentData 0 and 1 would have the same data when using content blocks sometimes or it would give you the completely wrong data context. And other times you won't even be able to get to the data context you want. I wonder if this issue is related?

@stubailo
Copy link
Contributor

They are related, I also want to fix that one right now.

@rclai
Copy link
Author

rclai commented Jan 23, 2015

Should I still post a reproduction for that one?

@stubailo
Copy link
Contributor

No I have one that's pretty good I think

@rclai
Copy link
Author

rclai commented Jan 25, 2015

How would I go about using this patch on demand before the next release happens? Is that possible?

@stubailo
Copy link
Contributor

After we fix this, we might be able to publish a pre-release version of Blaze, since that's the only package affected by the changes. I'll let you know.

@rclai
Copy link
Author

rclai commented Jan 26, 2015

Thanks.

@glasser glasser added the Blaze label Jan 27, 2015
@stubailo
Copy link
Contributor

try running your app with meteor --release TEMPLATE-CURRENT-DATA@0.0.1, this includes the fix we just merged for this issue. let me know if it's fixed!

@rclai
Copy link
Author

rclai commented Jan 29, 2015

It's working great. Nested a bunch of contentBlocks (and elseBlocks too) and I'm able to get the template instance data. Also tested parentData, currentData with different indexes.

In the process, I noticed that UI.body broke. helpers weren't working there in this pre-release (but are working in the current stable release).
https://github.com/rclai/ui-body-issues
I was getting this error:

Uncaught TypeError: Cannot read property 'bind' of undefined

@stubailo
Copy link
Contributor

Interesting - this is actually a bug introduced in the preview, thanks for catching it!

@rclai
Copy link
Author

rclai commented Jan 30, 2015

No problem, let me know how it goes.

@stubailo
Copy link
Contributor

I think I have fixed it now. I forgot you can have helpers on Template.body, which is not technically a template.

@rclai
Copy link
Author

rclai commented Jan 31, 2015

One thing I noticed also about the current release is that you can't call Template.instance() inside of UI.body's helpers for some reason. It'll give you this error:

Exception in template helper: TypeError: undefined is not a function
    at Function.Template.instance (http://localhost:3000/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:3172:15)
    at Object.Template.body.helpers.huh (http://localhost:3000/todo.js?369894fe370de6099d78041d62a01b22fd3afe59:8:23)
    at bindDataContext (http://localhost:3000/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2727:16)
    at Blaze._wrapCatchingExceptions (http://localhost:3000/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1606:16)
    at Spacebars.call (http://localhost:3000/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:171:18)
    at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:108:25)
    at Object.Spacebars.mustache (http://localhost:3000/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:112:39)
    at null._render (http://localhost:3000/template.todo.js?8adea1cfbcc0c100fb92a17b2b10d75cdbbbf9bc:5:22)
    at doRender (http://localhost:3000/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1866:25)
    at http://localhost:3000/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1808:16

Could this be related to the above bug?

Here's a reproduction (I hope you don't mind that I pasted it here given how small it is?):

if (Meteor.isClient) {
  Template.body.created = function () {
    this.test = 'huh'
  };

  Template.body.helpers({
    huh: function () {
      return Template.instance().test;
    }
  });
}

<body>
  {{huh}}
</body>

@rclai
Copy link
Author

rclai commented Feb 2, 2015

What's the status of this?

@stubailo
Copy link
Contributor

stubailo commented Feb 3, 2015

This is interesting - I think Template.body is not a real template, and therefore doesn't really have Template.instance(). @avital @dgreensp what should we do here?

@rclai
Copy link
Author

rclai commented Feb 3, 2015

I'm bringing up Template.body or UI.body because it's mentioned in here.

@stubailo
Copy link
Contributor

stubailo commented Feb 3, 2015

Oh interesting, I could be wrong then, let me look into it more

@stubailo
Copy link
Contributor

stubailo commented Feb 3, 2015

Just opened a new issue for this: #3631

@stubailo
Copy link
Contributor

stubailo commented Feb 3, 2015

Going to close this because this particular issue has been fixed

@stubailo stubailo closed this as completed Feb 3, 2015
@rclai
Copy link
Author

rclai commented Feb 3, 2015

Ok cool thanks.

martijnwalraven pushed a commit that referenced this issue Feb 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants