How to import a recursive stache template

(Don’t know it this is the right forum)
When I try to import a stache template that has a recursive loop, I get an error.

Uncaught Error: can.view: No template or empty template:recursive_template.mustache
Info: can/view/view.js: There is no template or an empty template at upload_main_tree_views_smscTree_stache.mustache

I import the template like this:

import recursive_template from './views/template.stache';

The template is used like this:

this.element.html(recursive_template({children: items}));
```

The template looks like this.
If there are children, it uses the same template again.

```
<ul>
	{{#each children}}
		<li>
			...
			{{#hasChildren}}
				{{>recursive_template}}
			{{/hasChildren}}
		</li>
	{{/each}}
</ul>
```

The documentation states that the {{>key}} can also be a function, right?
https://canjs.com/docs/can.stache.helpers.partial.html

Or, do I have to register the template somehow?

Does:

var frag = recursive_template(
  {children: items}, 
  {
    partials: {recursive_template: recursive_template}
  })
this.element.html(frag);

work?

1 Like

Thx, Justin. That works.