-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Custom block helper hides template instance #2923
Comments
You're right, this makes it pretty difficult to combine helpers that access the template instance with custom block helpers. It's a little scary to think about changing how |
I worked around this issue looking up the chain of parentView until you find the property you're looking for: BlazeComponent.getFirstInstance = function(property){
var comp = UI._templateInstance();
if(comp[property])
return comp[property];
var view = comp.view.parentView;
while(!view._templateInstance || !view._templateInstance[property]){
view = view.parentView;
}
return view._templateInstance[property];
}; |
The (simpler) workaround we've been using goes like this:
The big caveat is you can only have one instance of each template at once if you do this. But that's usually fine. |
Thanks for the tips. I use (i declare only 1 template per file) a simple "var" decleration on top of each file for now. Which seems to have the same effect. Thing is, this defeats the whole purpose of wanting something different than Session.get() in the first place, being able to use it on more instances at once :) This is related I guess #2573 |
This is quite a pain actually. Any progress on this? I would love to have |
#3545 is fixing this! |
When assigning properties to a template instance in the
created
method of a template and a helper of that template is invoked inside a custom block helper, which is in turn invoked inside the actual template, the template instance ofTemplate.instance()
will be that of the custom block helper and not of the "real" template. For example, consider this:and
notVisibleString
is usingTemplate.instance()
to access a property of the template instance; then that instance will be that ofcontentBlock
and nottemplateBug
, which to me is counter intuitive and makes it difficult to use a custom block helper with assigning properties to a template instance inTemplate.myTemplate.created
.Steps to reproduce
Example project which visualizes this here: https://github.com/lbergnehr/meteor_template_content_block_bug
this will not show the intended text, whereas removing the content block will:
The text was updated successfully, but these errors were encountered: