No way to access child templates?

Hi. I couldn’t find a way to access child templates. I have an “item” template that can have many child “item” templates inside and I need to access them. Is there a way to do it?

Also there’s no easy way of accessing parent templates other than using custom function with some kind of iteration through the parents. Am I correct?

If this is the case I think this is a very big missing feature in Blaze.

Thanks!

Check this out: https://www.discovermeteor.com/blog/a-guide-to-meteor-templates-data-contexts/

Yes, this is a missing feature, which has already been requested. Right now you could use aldeed/meteor-template-extension’s template.parent function which works great.

Thanks guys.

@orbyt That tutorial only talks about accessing parents, but not children. Even to access parents I have to create my own function or use aldeed’s package.

@fvg The only method I could find to get children templates is using the https://github.com/peerlibrary/meteor-blaze-components#accessing-data-context library. Aldeed’s library only provides acess to parents, but not children.

I think accessing children is something basic that should be provided by the official API. I hope this changes in the future!

1 Like

You asked: [quote]Also there’s no easy way of accessing parent templates other than using custom function with some kind of iteration through the parents. Am I correct?[/quote]

but k

@orbyt sorry if I wasn’t clear in my question. I can access parent templates but I use a function like this (that I got from someone I don’t remember in what forum):

Blaze.TemplateInstance.prototype.searchParentTemplate = function (levels) {
var view = Blaze.currentView;
if (typeof levels === "undefined") {
    levels = 1;
}
while (view) {
    if (view.name.substring(0, 9) === "Template." && !(levels--)) {
        return view.templateInstance();
    }
        view = view.parentView;
    }
}

This shouldn’t be this hard. Hopefully the meteor guys will solve it in the seemingly upcoming the componets package.

The manuel:viewmodel package (for children/parent/sibling/accesing helpers) and using _uihooks (to have control on changes in the DOM inside a template) solved all my problems with Blaze.

http://viewmodel.meteor.com/
http://www.webtempest.com/meteorjs-animation

I hope it helps!