Skip to content
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

Run-time compiled templates not initialising nested templates #21

Open
Rob-pw opened this issue Feb 20, 2015 · 1 comment
Open

Run-time compiled templates not initialising nested templates #21

Rob-pw opened this issue Feb 20, 2015 · 1 comment

Comments

@Rob-pw
Copy link

Rob-pw commented Feb 20, 2015

Hi Soundstep:

http://plnkr.co/edit/gHwT7PPCgpjIjv2pIcfT?p=preview

Is this expected functionality? I require that a template can be compiled from mark-up, instantiating any templates contained in that markup.

This is more my situation:

function XTemplate (template, scope, element) {
  var markup = require('./templates/_xTemplate.html');

  template.compile();
  scope = template.scope;
}

_xTemplate.html

<div data-template="YTemplate"></div>
<div data-template="ZTemplate"></div>

If this issue won't be fixed for a while, how might I circumvent this limitation for the time being?

Many thanks, hope you are doing well.

Yours,
Rob.

@soundstep
Copy link
Owner

The data-template is kind of a shortcut but should probably not be used for something more complicated.

If you look at the code, the data-template is parsed on a DOM Ready event, so I'm not surprised it is not parsed again on an async call:

https://github.com/soundstep/soma-template/blob/master/build/soma-template.js#L1468

It is also a bit strange to use data-template, and then re-compile it with another piece of html.

I suggest you instantiate the templates yourself rather than using the data-template attribute.

target.innerHTML = partials['body.tpl.html'];
var template = soma.template.create(target.firstChild);
var scope = template.scope;

In case that helps, if you don't want to asynchronously loads your html. I've created a grunt plugin to convert html to javascript:

https://www.npmjs.com/package/grunt-html-convert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants