googlearchive / TemplateBinding

TemplateBinding Prolyfill
290 stars 61 forks source link

When template.createInstance is used with a nested template, the nested template's content is empty #144

Closed sorvell closed 10 years ago

sorvell commented 10 years ago

See console output in this example: http://jsbin.com/OViviwi/1/edit

When cloneNode(true) is used on a template's content to stamp a nested template, the nested template content is intact. However, when createInstance is used, the nested template's content is blank.

sethladd commented 10 years ago

/sub

rafaelw commented 10 years ago

So this is currently working as designed, but I agree it's somewhat surprising.

It's not really worth a long explantation, but this is basically a side-effect of how Node.bind() works (any sub-templates have had Node.bind() called on them, but they haven't reacted by building their instances yet).

It'd be helpful to understand more the use case for calling createInstance() and doing work synchronously with the result which requires all sub-instances to be stamped.

labriola commented 10 years ago

Take a look at these two jsBins for an example use case of what I am trying to do... at least what led us here.

In the first, I am passing the needed templates in as content, and then querying them. All works well, but its not exactly what I want to do: http://jsbin.com/ugikeDa/2/edit?html,output

In the second, I am trying to include the templates within the polymer component itself. This is more practical for my use case, but I can't seem to get the magic combination to get it to work. http://jsbin.com/ugikeDa/3/edit?html,output

Yes, I know for this simple example there are other ways to do this in the template with binding, etc. but my actual component is more complex. This shows the specific issue I am encountering well, which boils down to:

How does an element maintain templates for variable content without polymer stripping the content?

rafaelw commented 10 years ago

I think for this kind of use you don't want to use an instantiating template directive. there's no point in telling