These are chat archives for canjs/canjs

20th
Feb 2018
Jeroen Cornelissen
@jeroencornelissen
Feb 20 2018 14:08

Is it possible to create can-templates on the fly?

<tree-item vm:item:bind=“item">
  <can-template name=“tpl”>{{{getTemplate(item.type)}}}</can-template>
</tree-item>
<can-slot name=“tpl” />

I’ve tried this, but that won’t render my template.
the getTemplate function returns a string like <span>{{name}}</span>.

Gregg Roemhildt
@roemhildtg
Feb 20 2018 14:11
I think you might have a scope issue. In your can-slot you might have to do item:bind="item"
Also, you could try the partial syntax {{>getTemplate(item.type)}}
Try using {{debugger()}} in your can-template and make sure getTemplate and item are accessible
Jeroen Cornelissen
@jeroencornelissen
Feb 20 2018 14:22
@roemhildtg even if I add item:bind=“item” to can-slot, the stache doesn’t parse and renders {{name}} to the screen.
Jeroen Cornelissen
@jeroencornelissen
Feb 20 2018 20:25
Here is an example of what I’m trying to do.
https://jsbin.com/cofitagixu/edit?js,output
I’d like to use <can-template/> instead of {{{tpl}}}, but I don’t know if that is possible.
Jeroen Cornelissen
@jeroencornelissen
Feb 20 2018 20:32
Another question, what’s the best way to pass a property from my app to test-tree to tree-item to test-tree?
See the config prop in this example, https://jsbin.com/falupiyali/1/edit?js,output
config is only needed in test-tree component, but tree-item creates a new test-tree.
Gregg Roemhildt
@roemhildtg
Feb 20 2018 21:35
I think you just had a couple of scope issues/binding issues (using to vs. from) .
Also you should move your sub component test-tree into the slot
Both each and <component-tag> create's their own parent scope so you need to do ../.. to access the config inside the <can-template